ठीक है मुझे यह कोड मिला है:
$(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'));
}
मैं क्लिक ईवेंट के लिए एक नया फ़ंक्शन कैसे निर्दिष्ट या सेट कर सकता हूं?
$ ("# डायलॉग_प्रिंट-बटन")। ???
संपादित करें, यह काम करता है:
$("#dialog_print-button").unbind("click").click(
function () {
alert("new function that overide the old ones")
}
)
JQuery दस्तावेज़ीकरण में कैसे करना है, यह जानने का प्रयास किया लेकिन मुझे लगता है कि दस्तावेज़ीकरण में इसे खोजना मुश्किल है। खासकर जब जावास्क्रिप्ट और jQuery libary के लिए नया।
संपादित करें, सहायता प्राप्त करने का एक तेज़ तरीका है jQuery के आईआरसी चैनल पर जाना :D
4 जवाब
$("#Print page").click(function () {
...
});
या शायद यह होना चाहिए
$("#dialog_print-button").click(function () {
...
});
मुझे लगता है कि इससे मदद मिलेगी:
$(".dialogDiv").dialog("option", "buttons", {
"Print page": function() { /* new action */ },
"Cancel": function() { $(this).dialog("close"); }
});
क्योंकि buttons
प्रॉपर्टी सभी बटन सेट करती है, आपको cancel
बटन हैंडलर शामिल करना होगा।
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"); },
}
]
});
आप कोड को बटन सेक्शन में रखें:
...
buttons: {
"Print page": function() {
//here you execute the code or call external functions as needed
}
एक बार जब आप डायलॉग पर बटन पर क्लिक करते हैं, तो वह कोड अपने आप आ जाता है। इसलिए आप वहां सीधे वह कोड डालते हैं जो आपके तर्क को लागू करता है।