设置jQuery UI对话框按钮ID?
是否可以在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();
$("#myDialog").dialog({ buttons : { "MyButton" : { text: "OK", id: "okbtnid", click: function(){ var bValid = true; } } } });
或者你可以把它作为一个数组:
$("#myDialog").dialog({ buttons : [{ text: "OK", id: "ok", click: function(){ alert("clicked"); } }] });
不是通过你想要的方式,因为API不提供这些选项,但是如果你查看对话框生成的标记,你应该能够抓住你需要的任何元素并根据需要绑定它们或向它们添加id。 这是文档页面中的标记(http://jqueryui.com/demos/dialog/)
如果它是模态内容中的按钮,那么你可以在模态元素上下文中进行CSS查询,并以这种方式访问它们。