मैं एक 2 jQuery एक scripts- इससे पहले कि मैं .preventDefault जोड़ा है, और एक ही स्क्रिप्ट की एक प्रति के बाद मैं .preventDefault गयी। jQuery प्रारंभिक में काम करता है, लेकिन नहीं मैं .preventDefault()jQuery .preventDefault();
प्रारंभिक स्क्रिप्ट काम करता है
$(window).load(function(){
$(document).ready(function(){
$("span[id$='_ff5_1']").each(function() { //returns a collection of elements that must be iterated through using each
if ($(this).text() == "Yes") { //test value returned from non-input field
clearID();
$("tr.anon").hide();
} else {
$("tr.anon").show();
}
});
if ($("select[title='action']").val() == "") {
$("tr.actDet").hide();
}
$("select[title='organizationalElement']").focusout(function() {
if ($(this).val() === "I don\'t know") {
alert("If no organizational element is selected, additional time may be required to route this request");
} // close if
$("select[title='action']").change(function(){
$(".actDet").toggle($(this).val()!= "");
}); // close action.change
});//close select.focusout
}); // close doc.ready
}); // close window.load
स्क्रिप्ट वह काम नहीं करता ...
$(window).load(function(){
$(document).ready(function(){
$("span[id$='_ff5_1']").each(function() { //returns a collection of elements that must be iterated through using each
if ($(this).text() == "Yes") { //test value returned from non-input field
clearID();
$("tr.anon").hide();
} else {
$("tr.anon").show();
}
});
if ($("select[title='action']").val() == "") {
$("tr.actDet").hide();
}
$("select[title='organizationalElement']").focusout(function() {
if ($(this).val() !== "I don\'t know") {
$(this).preventDefault();
} else {
alert("If no organizational element is selected, additional time may be required to route this request");
} // close if
$("select[title='action']").change(function(){
$(".actDet").toggle($(this).val()!= "");
}); // close action.change
});//close select.focusout-- close edit record stuff
}); // close doc.ready
}); // close window.load
केवल परिवर्तन जोड़ने के बाद मैंने बनाया प्रारंभिक है अगर कथन एक/अन्य है जो .preventDefault() को कॉल करता है। पहली लिपि महान काम करती है, लेकिन दूसरी लिपि विफल हो जाती है। क्यूं कर? मैं .preventDefault() विधि फोन कर रहा हूँ अगर organizationalElement का मूल्य एक मौजूदा रिकॉर्ड पर IDK है।
@Andrew: आपके संपादन के स्पष्ट करने के लिए ... मैं करने के लिए मेरी स्क्रिप्ट को संशोधित करना चाहिए: ...
if ($(this).val() !== "I don\'t know") {
$(this).click(function(e) { e.preventDefault(); });
} else {
alert("If no organizational element is selected, additional time may be required to route this request");
} // close if
... b/c मैं ध्यान दिया taht इसे सही ढंग से काम करेंगे अगर मैं बदल $ (this) .preventDefault(); e.preventDefault();
आप शायद यह कैसे लिखने के लिए अगर मैं $ करने के लिए विधि संलग्न करने के लिए (यह) वस्तु के रूप में मैं मूल रूप से यह लिखा था इच्छा दिखाने की कोशिश कर रहे हैं?
धन्यवाद एडम।मुझे पता है कि रोकथाम डीफॉल्ट घटना को बुलबुले से नहीं रोकता है, हालांकि मुझे यकीन नहीं है कि मैं बुलबुले नहीं चाहता हूं। क्या शायद यह पूरी jQuery स्क्रिप्ट को काम करने से रोकता है? – jg100309
@ jg100309 - नहीं, आपकी मूल समस्या यह थी कि आप ईवेंट ऑब्जेक्ट की बजाय रोकथाम को कॉल कर रहे थे। इवेंट ऑब्जेक्ट को अपने हैंडलर पर पास करें, और * it * पर preventDefault को कॉल करें, जैसे कि मेरे उत्तर –
* साइड नोट: यदि आपको दो '' s * * – SeinopSys