我正在尝试通过Magnific弹出框制作弹出菜单/模式框。
//Dynamic button:
Button btn1 = new Button
{
Text = "Button1"
};
btn1.Attributes.Add("onClick", "javascript:return openForm();");
How do you think it is possible to write a script like this:
<script type="text/javascript">
function openForm() {
$('.popup-with-form').magnificPopup({
type: 'inline',
focus: '#name'
});
}
</script>
或者如何将动态按钮与此脚本关联?
<!-- The Modal -->
<div id="form-popup" class="white-popup mfp-hide">
<div runat="server" action="#">
<div><input id="name" class="inputbox" type="text" placeholder="Your name" /></div>
<div><input id="email" class="inputbox" type="email" placeholder="Your e-mail" /></div>
<div><textarea name="mess" id="mess" class="inputbox" cols="30" rows="10" placeholder="Your message"></textarea></div>
<div><input type="submit" value="Send"></div>
</div>
</div>
并且这样做是否有误,请用div替换form:
<form action="#"> -----> <div runat="server" action="#">
编辑1
实时演示:https://stackblitz.com/edit/js-6qdlqt?file=index.html
尝试这些更改。
弹出窗口:
<div id="form-popup" class="white-popup mfp-hide">
<div runat="server" action="#">
<div><input id="name" class="inputbox" type="text" placeholder="Your name" /></div>
<div><input id="email" class="inputbox" type="email" placeholder="Your e-mail" /></div>
<div><textarea name="mess" id="mess" class="inputbox" cols="30" rows="10" placeholder="Your message"></textarea></div>
<div><input type="submit" value="Send"></div>
</div>
</div>
弹出样式:
.white-popup {
position: relative;
background: #FFF;
padding: 20px;
width: auto;
max-width: 500px;
margin: 20px auto;
}
脚本初始化:
$(function () {
$('#btnOpenPopup').magnificPopup({
type:'inline',
closeBtnInside: true
});
});
动态按钮:
Button btn1 = new Button
{
ID = "btnOpenPopup",
Text = "Button1"
};
btn1.Attributes.Add("data-mfp-src", "#form-popup");
插件文档:
https://dimsemenov.com/plugins/magnific-popup/documentation.html