Bootstrap“JQuery:如何启用”;“必需”;表单提交期间字段的验证单击?
以下是JS代码:Bootstrap“JQuery:如何启用”;“必需”;表单提交期间字段的验证单击?,jquery,validation,jsp,bootstrap-4,jquery-ajax,Jquery,Validation,Jsp,Bootstrap 4,Jquery Ajax,以下是JS代码: $('#createCust').on('click', function(e) { e.preventDefault(); documentCommon.ajax({ dataType : 'text', url : "/createcustomer", data : $("body form:first
$('#createCust').on('click', function(e) {
e.preventDefault();
documentCommon.ajax({
dataType : 'text',
url : "/createcustomer",
data : $("body form:first").serialize(),
success : function(data) {
$(".dialogTitle").html("");
$(".dialogTitle").html("Add Customer");
$(".actualData").html("");
$(".actualData").html(data);
$('#modalViewDialog').modal('show');
}
});
});
以下是按钮:
<form:form method="POST" modelAttribute="customerForm"
class="form-signin" action="/createcustomer">
<form:input type="text" path="customerName" class="form-control"
placeholder="Customer Name" required="required"></form:input>
<button type="submit" id="createCust" class="btn btn-primary">Create</button>
创造
当我删除JS代码时,它可以正常工作,但我需要ajax调用,所以我不能依赖整个页面提交。还有什么方法可以在JS调用中启用所有必需的字段检查吗?实现上述功能的另一种方法是使用
检查输入是否为空“”
并根据这一点进行ajax调用或显示错误
下面是一个示例,如果您知道输入的名称,并且希望手动检查每个输入
演示代码:
$('createCust')。在('click',函数(e)上{
e、 预防默认值();
//检查客户是否为空
if($(“输入[name='customerName']”)。val()!=“”){
log(“转到后端”)
/*您的ajax调用*/
}否则{
//做点什么来显示错误
控制台日志(“请在上面填写”)
}
});代码>
创造
实现上述目标的另一种方法是使用!=“”
并根据这一点进行ajax调用或显示错误
下面是一个示例,如果您知道输入的名称,并且希望手动检查每个输入
演示代码:
$('createCust')。在('click',函数(e)上{
e、 预防默认值();
//检查客户是否为空
if($(“输入[name='customerName']”)。val()!=“”){
log(“转到后端”)
/*您的ajax调用*/
}否则{
//做点什么来显示错误
控制台日志(“请在上面填写”)
}
});代码>
创造
这是什么documentCommon
尝试更改$。ajax
我没有看到关于jQuery验证插件的任何问题。移除标签。它是什么documentCommon
尝试更改$。ajax
我没有看到关于jQuery验证插件的任何问题。移除标签。