Может ли кто-нибудь помочь мне узнать, почему этот скрипт не работает? После нажатия кнопки «Отправить» моя форма все еще отправляется.e.preventDefault не работает 2
Вот код:
submitadd.submit(function(e){
var submitadd = jQuery('#submitadd'),
yearofmanufacturing = jQuery('#yearofmanufacturing'),
price = jQuery('#price'),
addtext = jQuery('#addtext');
if(yearofmanufacturing.val()==''){
jQuery('#yearofmanufacturing').addClass('bordered2');
jQuery('#yearofmanufacturing').removeClass('styled_select');
jQuery("#yearofmanufacturing").attr("placeholder", "Εισάγετε Χρονολία").placeholder();
e.preventDefault();
return false;
alert('yearof......enter in the if');
}
else {
alert("yearnotempty?");
}
if(price.val()=='') {
jQuery('#price').addClass('bordered2');
jQuery('#price').removeClass('styled_select');
jQuery("#price").attr("placeholder", "Εισάγετε τιμή").placeholder();
e.preventDefault();
return false;
alert('price...enter in the if');
}
if(addtext.val()==''){
jQuery('#addtext').addClass('bordered2');
jQuery('#addtext').removeClass('styled_select');
jQuery("#addtext").attr("placeholder", "Εισάγετε περιγραφή αγγελίας").placeholder();
e.preventDefault();
return false;
alert('add text...enter in the if');
}
alert('addtext = ' +addtext.val());
});
Ни одно из предупреждений не показывает, когда подавать была нажата. Любая помощь будет глубоко оценена.
Regard, Джон
Проверьте ошибки на консоли. – ZiNNED
'submitadd' что это? – Jai
Не знаете, почему! но "return false"; вместо preventDefault() должен сделать трюк. – lshettyl