这是用于 ajax html 弹出窗口的 javascript
<script type="text/javascript">
$(document).ready(function() {
$('.ajax-popup-link').magnificPopup({
type: 'ajax',
overflowY: 'scroll',
closeOnContentClick: false
});
});</script>
这是按钮代码
<input id="btn" type="button" value="click" onclick="myFunction();"/>
我有一个弹出 html 文件名 test.html,我需要在单击按钮时将其作为弹出窗口打开
最佳答案
将您的 ajax 代码绑定(bind)到 myFunction()
,例如:
function myFunction(){
// your code
$('.ajax-popup-link').magnificPopup({
type: 'ajax',
overflowY: 'scroll',
closeOnContentClick: false
});
}
或者从 html 输入中删除 onclick 并将其添加到您的脚本中
$( "#btn" ).click(function() {
$('.ajax-popup-link').magnificPopup({
type: 'ajax',
overflowY: 'scroll',
closeOnContentClick: false
});
});
关于javascript - 如何从javascript为按钮onclick选项创建一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30163935/