我让jQuery通知根据某些选择发布警告消息:我需要做的是在警告/通知消息出现时不要提交表单。仅当错误解决后,才提交表单。单击btnQuoteVariances时,将提交表单。问题是notify不是函数,因此我不能在这里真正使用return false或event.preventDefault()。
$('.Reason').change(function(event)
{
var id = $(this).data('item-id');
var sPrice = $(this).data('price');
var reason = $(this).val();
var aPrice = $(this).data('aPrice');
if (reason > 0 && (aPrice == sPrice)){
$('##' + id).notify(
{
title: 'Warning',
text: "Both pricing can't match, Please fix before conitniuing.",
image: '<i class="fa fa-2x fa-exclamation-circle"></i>'
},
{
style: 'cosentino',
className: 'error',
position: 'top center',
clickToHide: true,
autoHide: false
});
}
$('##frmJobEntry').validate(
{
errorClass: 'JoblineInlineError'
});
$("##btnQuoteVariances").click(function(event)
{
$('.txtShopPrice').prop('disabled', false);
$('.txtRevisedUnitPrice').prop('disabled', false);
});
也许
$("form").on("submit",function(e) {
const $reason = $(".reason");
const id = $reason.data('item-id');
const sPrice = $reason.data('price');
const reason = $reason.val();
const aPrice = $reason.data('aPrice');
if (reason > 0 && (aPrice == sPrice)){
e.preventDefault();
}
})