5
5

More than 5 years have passed since last update.

【javascript】jQuery-UI-dialogに独自ボタンを付ける方法

Posted at

jQuery-UIのダイアログに独自のボタン(buttonsオプションでない)をつけて自由自在にイベントを呼びたい場合

保存して閉じるボタンとキャンセルして閉じるボタンの動きを分けたい場合

その他自在に呼び出す前にコールバック関数を渡したい場合

だいぶソースきたないですが
こう。

javascript
$("<div><button onclick='parent.$(\".ui-dialog-content\").trigger(\"save\");'>ほぞん</a></div>").dialog({
  close:function(){
    alert("クローズなう")
  }
  ,buttons:{
    "保存": function() {
      $(this).trigger("save");
    }
    ,"閉じる":function(){
      $(this).trigger("abortme");
    }
  }
})
.on("save", function(){
  alert("セーブなう");
  $(this).dialog("close");
})
.on("abortme", function(){
  $(this).dialog("close");
})

要は

1.親ウインドウからダイアログ呼び出し時にonメソッドで独自イベント定義
2.buttonsオプションからイベントをセットするときは$(this).trigger("/*event*/");
  dialogの中身のHTMLに直接イベント書くときはparent.$(".ui-dialog-content").trigger("/*event*/")とする

これでOK

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5