jquery点击href链接 - 必须点击两次 [英] jquery click on href link - have to click twice
本文介绍了jquery点击href链接 - 必须点击两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此函数可以正常工作,但只有在按钮被点击两次后,弹出框才会打开(然后,后续点击会获得第一次点击的操作)。
The function works, but the popup will open only after the button is clicked twice (and then, subsequent clicks get the action on the first click).
$(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;
});
});
有什么问题?
推荐答案
我认为这是因为你实际上在点击
处理程序中初始化插件。从快速浏览到 popupWindow
文档,看起来插件会为你绑定点击
处理程序意味着您的第一次点击绑定弹出功能(包括onclick处理程序),因此它只适用于第二次点击。我会尝试:
I think that is because you are actually initialising the plugin within the click
handler. From a quick skim through the popupWindow
docs it appears that the plugin takes care of binding a click
handler for you, which means that your first click binds the popup functionality (including an onclick handler) so it only works upon click a second time. I would try:
$(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();
});
});
这篇关于jquery点击href链接 - 必须点击两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文