该功能有效,但弹出窗口仅在单击按钮两次后才会打开(然后,后续点击会在第一次点击时获得操作)。
$(document).ready(function(){
$('a#printPosBtn').on('click', function(e) {
e.preventDefault();
$('.printPopup').popupWindow({
centerBrowser:1,
height:500,
width:720,
scrollbars: 1,
resizable: 1
});
return false;
});
});
怎么了?
答案 0 :(得分:3)
我认为这是因为您实际上是在click
处理程序中初始化插件。从快速浏览popupWindow
文档看来,插件会为您绑定一个click
处理程序,这意味着您的第一次单击会绑定弹出功能(包括一个onclick处理程序),所以它只是第二次点击即可使用。我会尝试:
$(document).ready(function() {
$(".printPopup").popupWindow({
centerBrowser: 1,
height: 500,
width: 720,
scrollbars: 1,
resizable: 1
});
// open popup by clicking on some other element
$('#printPosBtn').on('click', function(e) {
e.preventDefault();
$(".printPopup").click();
});
});