[英]jQuery dialog button how to set the click event?
Ok i got this code: 好的,我有这个代码:
$(document).ready(
function() {
$(".dialogDiv").dialog({
autoOpen: false,
modal: true,
position: [50, 50],
buttons: {
"Print page": function() {
alert("Print");
},
"Cancel": function() {
$(this).dialog("close");
}
}
}
);
$('.ui-dialog-buttonpane button:contains("Print page")').attr("id", "dialog_print-button");
$(".dialogDiv").parent().appendTo($('form'));
}
How do I assign or set a new function to the click event? 如何为click事件分配或设置新功能?
$("#dialog_print-button"). $( “#dialog_print按钮”)。 ??? ???
Edit, This works: 编辑,这有效:
$("#dialog_print-button").unbind("click").click(
function () {
alert("new function that overide the old ones")
}
)
Tried to find how to do in the jQuery documentation but I think it's hard to find around in the documentation. 试图找到如何在jQuery文档中做,但我认为在文档中很难找到。 Especially when new to javaScript and the jQuery libary. 特别是当新手javaScript和jQuery库时。
Edit, A fast way to get help is to go to jQuery irc channel :D 编辑,获得帮助的快速方法是转到jQuery irc频道:D
I think this would help: 我认为这会有所帮助:
$(".dialogDiv").dialog("option", "buttons", {
"Print page": function() { /* new action */ },
"Cancel": function() { $(this).dialog("close"); }
});
Because buttons
property sets all the buttons, you have to include cancel
button handler. 因为buttons
属性设置了所有按钮,所以必须包含cancel
按钮处理程序。
$("#Print page").click(function () {
...
});
Or maybe it should be 或者它应该是
$("#dialog_print-button").click(function () {
...
});
jQuery UI dialog buttons now supports the "id" attribute natively. jQuery UI对话框按钮现在本身支持“id”属性。
$("#dialog-form").dialog({
autoOpen: false,
height: "auto",
width: 300,
buttons:
[
{
text: "Create Revision",
id: "btnCreateRev",
click: function () {
//code for creating a revision
}
},
{
text: "Cancel",
id: "btnCancel",
click: function () { $(this).dialog("close"); },
}
]
});
You put the code within the button section: 您将代码放在按钮部分中:
...
buttons: {
"Print page": function() {
//here you execute the code or call external functions as needed
}
Once you click the button on the Dialog, that code is automatically invoked. 单击对话框上的按钮后,将自动调用该代码。 Therefore you insert there directly the code that implements your logic. 因此,您直接插入实现逻辑的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.