2011-10-17 58 views
0

我試圖給底部面板上的按鈕添加一個名稱(不是顯示的文本),並且找不到一種方法。將名稱添加到JQuery對話框底部按鈕

這是我迄今爲止...

$("#dialog-import-from-existing").dialog({ 
     title: "Import From Existing", 
     autoOpen: false, 
     modal: true, 
     draggable: false, 
     resizable: false, 
     width: 500, 
     height: 525, 

      buttons: { 
       **name : "SubmitButton",** 
       "Import": function() { 
       $('#CreateForm').submit(); 
       $(this).dialog('close'); 
      }, 
      "Cancel": function() { 
       //Need to added the js files to Driver studio. 
       //$("models-to-add-container").effect("explode"); 
       $(this).dialog('close'); 
      } 
      } 
     }); 

我想有這個按鈕的名稱爲「提交按鈕」。

在此先感謝。

回答

0

按鈕選項有兩個API。您正在使用將按鈕標籤映射到點擊功能的原始更簡單的API。你也可以使用一組對象,這給你更多的控制權。

$("#dialog-import-from-existing").dialog({ 
    ... 
    buttons: [ 
     { 
      name: "SubmitButton", 
      text: "Import", 
      click: function() { 
       $("#CreateForm").submit(); 
       $(this).dialog("close"); 
      } 
     }, 
     { 
      text: "Cancel", 
      click: function() { 
       $(this).dialog("close"); 
      } 
     } 
    ] 
}); 

此API允許您傳遞任何可傳遞給.attr()加上事件處理程序的內容。

0

嘗試:

$("#dialog-import-from-existing").dialog({ 
    ... 
    open: function() { 
     $(this).parent().find('.ui-dialog-buttonpane button:contains("Import")'). 
      attr('name', 'SubmitButton'); 
    } 
}); 

(從jQuery UI Dialog Button Icons精製)