Is it possible to set the ID for the buttons in a jQuery UI dialog, so that I can refer to them later through jQuery? For example, trigger events, disable etc?
是否可以在jQuery UI对话框中设置按钮的ID,以便稍后通过jQuery引用它们?例如,触发事件,禁用等?
... 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();
3 个解决方案
#1
37
$("#myDialog").dialog({
buttons : {
"MyButton" : {
text: "OK",
id: "okbtnid",
click: function(){
var bValid = true;
}
}
}
});
#2
2
Or you can do it as an array:
或者你可以把它作为一个数组:
$("#myDialog").dialog({
buttons : [{
text: "OK",
id: "ok",
click: function(){
alert("clicked");
}
}]
});
#3
0
Not through the way you want as the API doesn't provide those options however if you look at the markup generated by the dialog box you should be able to grab whichever elements you need and bind them as you want or add ids to them. Here is the markup as found of the documentation page (http://jqueryui.com/demos/dialog/)
不是通过你想要的方式,因为API不提供这些选项,但是如果你查看对话框生成的标记,你应该能够抓住你需要的任何元素并根据需要绑定它们或向它们添加id。这是文档页面中的标记(http://jqueryui.com/demos/dialog/)
<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>
If it's buttons inside the content of the modal then you can do CSS queries in the modal element context and get access to them that way.
如果它是模态内容中的按钮,那么你可以在模态元素上下文中进行CSS查询,并以这种方式访问它们。
#1
37
$("#myDialog").dialog({
buttons : {
"MyButton" : {
text: "OK",
id: "okbtnid",
click: function(){
var bValid = true;
}
}
}
});
#2
2
Or you can do it as an array:
或者你可以把它作为一个数组:
$("#myDialog").dialog({
buttons : [{
text: "OK",
id: "ok",
click: function(){
alert("clicked");
}
}]
});
#3
0
Not through the way you want as the API doesn't provide those options however if you look at the markup generated by the dialog box you should be able to grab whichever elements you need and bind them as you want or add ids to them. Here is the markup as found of the documentation page (http://jqueryui.com/demos/dialog/)
不是通过你想要的方式,因为API不提供这些选项,但是如果你查看对话框生成的标记,你应该能够抓住你需要的任何元素并根据需要绑定它们或向它们添加id。这是文档页面中的标记(http://jqueryui.com/demos/dialog/)
<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>
If it's buttons inside the content of the modal then you can do CSS queries in the modal element context and get access to them that way.
如果它是模态内容中的按钮,那么你可以在模态元素上下文中进行CSS查询,并以这种方式访问它们。