एक और अधिक सुरुचिपूर्ण और तेजी से समाधान पर क्लिक करें और ऑन-KeyUp कोड जोड़ने की घटनाओं आप घटना सुनने
$("#form").validate({
submitHandler: function(form) {
form.submit();
},
onkeyup: function(element, event) {
if (event.which === 9 && this.elementValue(element) === "") {
return;
} else if (element.name in this.submitted || element === this.lastElement) {
this.element(element);
}
if (this.checkForm()) { // checks form for validity
$('a.submit').attr('class', 'submit btn btn-success'); // enables button
} else {
$('a.submit').attr('class', 'submit btn btn-danger disabled'); // disables button
}
},
onclick: function(element) {
// click on selects, radiobuttons and checkboxes
if (element.name in this.submitted) {
this.element(element);
// or option elements, check parent select in that case
} else if (element.parentNode.name in this.submitted) {
this.element(element.parentNode);
}
if (this.checkForm()) { // checks form for validity
$('a.submit').attr('class', 'submit btn btn-success'); // enables button
} else {
$('a.submit').attr('class', 'submit btn btn-danger disabled'); // disables button
}
}
})
निम्नलिखित सीएसएस कोड के साथ के रूप में इसके बजाय किसी अन्य को जोड़ने की इस प्रकार की जरूरत है बस डिफ़ॉल्ट ओवरराइड करने के लिए है प्रस्तुत ट्रिगर - आरंभ में अक्षम (3 वर्गों bootstrap):
<a onclick="if(!$(this).hasClass('disabled')) { $('#form').submit(); }" class="submit btn btn-danger disabled">button_save</a>
यह बहुत आसान केवल करने के लिए jQuery प्लग में areYouSure के साथ प्रयोग किया जा सकता है सक्षम प्रस्तुत जब वास्तविक बदलाव किए जाते हैं:
if (this.checkForm() && $('#form').hasClass('dirty')) { // checks form for validity
मूक का प्रयोग करने में प्लग आरंभ:
$('#form').areYouSure({'silent':true});
Phill, आप अंत में यह बाहर काम किया? क्या आप अपना अंतिम समाधान प्रदान कर सकते हैं? – Blair
@blairyeah - माइकल इरगॉयन – ripper234