我有以下 jQuery 代码。我第一次点击链接时,没有任何反应;但是,第二次单击该链接时,会发生预期的操作。
$("a[rel]").bind("click", function(){
$(".close_button_change_password").attr('id','change_password_'+$(this).attr('id'));
$(this).overlay({
// disable this for modal dialog-type of overlays
closeOnClick: true,
mask: {
color: '#fff',
loadSpeed: 200,
opacity: 0.8
}
});
});
这是我的 HTML:
<a href="#" rel="#change_password" id="1">change password</a>
有谁知道我该如何解决这个问题?在此先感谢您的帮助。
最佳答案
尝试
$("a[rel]").live("click", function(){ ....
或者您可以尝试...,但我认为这不会解决问题。
$("a[rel]").live("change", function(){ ....
并确保其在 DOM 中准备就绪。
您可以尝试阻止默认操作,也许这会干扰您的第一次点击。
$("a[rel]").bind("click", function(event){
event.preventDefault(); // <---------^^
$(".close_button_change_password").attr('id','change_password_'+$(this).attr('id'));
$(this).overlay({
// disable this for modal dialog-type of overlays
closeOnClick: true,
mask: {
color: '#fff',
loadSpeed: 200,
opacity: 0.8
}
});
});
关于javascript - jQuery 事件直到第二次点击才触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7083903/