最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JQuery-ui Dialog: How can I prevent default action when the user clicks on close button? - Stack Overflow

programmeradmin0浏览0评论

i'm using JQuery-ui dialog;

i'd like to perform my custom actions when user clicks on dialog's close button [X], but i'd like to prevent the closing event too!

i tried this code without success:

$( ".selector" ).dialog({
       close: function(event, ui) {
          event.preventDefault();
          //mycode              
          }
});

Even if i wrote the code above the dialog is closed bypassing my "preventDefault".

Thank you!

MV

i'm using JQuery-ui dialog;

i'd like to perform my custom actions when user clicks on dialog's close button [X], but i'd like to prevent the closing event too!

i tried this code without success:

$( ".selector" ).dialog({
       close: function(event, ui) {
          event.preventDefault();
          //mycode              
          }
});

Even if i wrote the code above the dialog is closed bypassing my "preventDefault".

Thank you!

MV

Share Improve this question asked Oct 5, 2010 at 14:35 MircoMirco 1892 silver badges10 bronze badges 1
  • maybe return false; ? :) Or just hide [x] button and add your own cancel button – Danil Commented Oct 5, 2010 at 14:38
Add a ment  | 

2 Answers 2

Reset to default 6

I've been looking for an answer to this too - so far the best I've e up with is

$( ".selector" ).dialog({
   beforeClose: function(event, ui) {
      //mycode              
      return false;
      }
});

$('.selector').bind('dialogbeforeclose', function(event,ui){
  alert('hello');
});

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论