2012-04-25 12 views
14

jQuery UIダイアログのボタンのIDを設定して、後でjQueryで参照できるようにすることはできますか?たとえば、イベントをトリガーし、無効にするなど?jQuery UIダイアログ・ボタンのidを設定しますか?

... in the dialog setup ... 
buttons: {    
    "Sök": function() { 
     var bValid = true; 
    }, 
    "OK": function() { 
     if (OK()) { 
      getStuffNoteringar($("#txtStuffId").val()); 
      $(this).dialog("close"); 
     } 
    } 

.... later on in some javascript code.... 

$('#OK').click(); 

答えて

34
$("#myDialog").dialog({ 
    buttons : { 
    "MyButton" : { 
     text: "OK", 
     id: "okbtnid", 
     click: function(){ 
      var bValid = true; 
     } 
     } 
    } 
}); 
+1

ニースはそれが文書化されたが、それはしないように働くだろう知りませんでした。 – GillesC

+2

[documentation](http://jqueryui.com/demos/dialog/#option-buttons)はidについては言及していませんが、テキストとクリックがあります:) – mprabhat

+0

ええ、属性は機能しません。この文書化されていない機能を知ってうれしい。ドキュメントから欠けているものは、常に知っている最高のものです:) – GillesC

0

あなたが好きな方法を通じてAPIは、しかし、それらのオプションを提供していないとして、あなたは、ダイアログボックスによって生成されたマークアップを見ればあなたが必要な方の要素をつかむことができるはずですし、あなたが望むようにそれらを結合しませんまたはそれらにidsを追加します。ドキュメントページ(http://jqueryui.com/demos/dialog/)で見られるようにここでのマークアップは、それがモーダルのコンテンツ内側のボタンだならば、あなたはモーダル要素にCSSクエリを行うことができます

<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable ui-resizable"> 
    <div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"> 
     <span id="ui-dialog-title-dialog" class="ui-dialog-title">Dialog title</span> 
     <a class="ui-dialog-titlebar-close ui-corner-all" href="#"><span class="ui-icon ui-icon-closethick">close</span></a> 
    </div> 
    <div style="height: 200px; min-height: 109px; width: auto;" class="ui-dialog-content ui-widget-content" id="dialog"> 
     <p>Dialog content goes here.</p> 
    </div> 
</div> 

ですコンテキストにアクセスし、そのようにアクセスします。

2

それとも、配列としてそれを行うことができます。

$("#myDialog").dialog({ 
    buttons : [{ 
    text: "OK", 
    id: "ok", 
    click: function(){ 
     alert("clicked"); 
    } 
    }] 
}); 

http://docs.jquery.com/UI/Dialog

関連する問題