jQuery UI 删除确认回调函数
我想使用 jQuery UI 来实现删除确认。我想使用链接来触发对话框。这是我的代码:
<a href="http://www.google.com" class="delete">delete</a>
<script type="text/javascript">
$(function(){
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
autoOpen: false,
buttons: {
"Okay": function() {
$( this ).dialog( "close" );
return true;
},
Cancel: function() {
$( this ).dialog( "close" );
return false;
}
}
});
$( ".delete" ).click(function() {
$( "#dialog-confirm" ).dialog( "open" );
return false;
});
});
</script>
我想要做的是,当用户单击“取消”时,它不执行任何操作。但是当用户点击“确定”时,那么它会继续转到www.google.com。
但是,无论我单击“确定”还是“取消”,都没有任何反应。有什么想法吗?
I wang to use jQuery UI to implement a delete confirmation. I want to use a link to trigger the dialog. Here's my code:
<a href="http://www.google.com" class="delete">delete</a>
<script type="text/javascript">
$(function(){
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
autoOpen: false,
buttons: {
"Okay": function() {
$( this ).dialog( "close" );
return true;
},
Cancel: function() {
$( this ).dialog( "close" );
return false;
}
}
});
$( ".delete" ).click(function() {
$( "#dialog-confirm" ).dialog( "open" );
return false;
});
});
</script>
What I want to do is, when the user click on cancel, it does nothing. But when the user click on okay, then it will continue to go to www.google.com.
However, no matter okay or cancel I click, it remains nothing happens. Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
即使你这样做:
你仍然无法访问 google,因为在调用处理程序之后,jQuery 会触发对象上的事件。如果元素不是链接,它仅调用单击事件的本机处理程序。
您可以执行以下操作:
或者,您可以在页面上设置一个隐藏链接,如下所示:
然后,单击“打开”按钮时,您可以执行以下操作:
Even if you do this:
You still won't get to google, because after it calls handlers, jQuery triggers an event on the object. It only calls native handlers for click events if the element is not a link.
You could do something like this:
Or, you could have a hidden link on the page, like this:
Then, on the click of the "Open" button, you could do this: