猿问

如何在 asp.net 从动态按钮调用javascript?

我正在尝试通过Magnimic弹出式广场制作一个弹出菜单/模式框。


     //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 action="#">     ----->   <div runat="server" action="#"> 


杨__羊羊
浏览 147回答 1
1回答

幕布斯7119047

编辑 1现场演示:https://stackblitz.com/edit/js-6qdlqt?file=index.html请尝试这些更改。弹出窗口:<div id="form-popup" class="white-popup mfp-hide">&nbsp; &nbsp; <div runat="server" action="#">&nbsp; &nbsp; &nbsp; <div><input id="name" class="inputbox" type="text" placeholder="Your name" /></div>&nbsp; &nbsp; &nbsp; <div><input id="email" class="inputbox" type="email" placeholder="Your e-mail" /></div>&nbsp; &nbsp; &nbsp; <div><textarea name="mess" id="mess" class="inputbox" cols="30" rows="10" placeholder="Your message"></textarea></div>&nbsp; &nbsp; &nbsp; <div><input type="submit" value="Send"></div>&nbsp; &nbsp; </div></div>弹出窗口样式:.white-popup {&nbsp; position: relative;&nbsp; background: #FFF;&nbsp; padding: 20px;&nbsp; width: auto;&nbsp; max-width: 500px;&nbsp; margin: 20px auto;}脚本初始化:$(function () {&nbsp; $('#btnOpenPopup').magnificPopup({&nbsp; &nbsp; type:'inline',&nbsp; &nbsp; closeBtnInside: true&nbsp; });});动态按钮:&nbsp; Button btn1 = new Button&nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; ID = "btnOpenPopup",&nbsp; &nbsp; &nbsp; &nbsp; Text = "Button1"&nbsp; &nbsp; &nbsp; };&nbsp; btn1.Attributes.Add("data-mfp-src", "#form-popup");插件文档:https://dimsemenov.com/plugins/magnific-popup/documentation.html
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答