Javascript 同时验证表单和一些输入
这里我有一个表单,我需要验证表单。我选择了2个输入字段,这个字段我不能用欧芹插件验证,所以我写我的代码 问题是如何同时检查Javascript 同时验证表单和一些输入,javascript,jquery,forms,validation,Javascript,Jquery,Forms,Validation,这里我有一个表单,我需要验证表单。我选择了2个输入字段,这个字段我不能用欧芹插件验证,所以我写我的代码 问题是如何同时检查validate=true和选择2inputs===null 我写道: $(function() { $('#myForm').submit(function(e) { e.preventDefault(); if ( $(this).parsley('validate') ) {
validate=true
和选择2inputs===null
我写道:
$(function() {
$('#myForm').submit(function(e) {
e.preventDefault();
if ( $(this).parsley('validate') ) {
if ($("#parcele").select2("data")== null || $("#vrsta_rada").select2("data")== null) {
$('#parerror').show();
console.log('nema dalje');
} else {
var zemljiste = $("#parcele").select2("data").naziv;
var id_parcele = $("#parcele").select2("data").id;
var vrsta_rada = $("#vrsta_rada").select2("data").text;
$.ajax({
url: "insertAkt.php",
type: "POST",
async: true,
data: { naziv:$("#naziv").val(),parcele:zemljiste,vrsta_rada:vrsta_rada,opis:$("#opis").val(),pocetak:$("#pocetak").val(),zavrsetak:$("#zavrsetak").val(),status:$("#status").val(),id_parcele:id_parcele,}, //your form data to post goes here as a json object
dataType: "html",
success: function(data) {
$('#myModal').modal('hide');
drawVisualization();
console.log('USPEH');
console.log(data);
},
error: function (data) {
console.log(data);
console.log('GRESKA NEKA');
}
});
}
}
});
});
但正如您所看到的,我的代码首先检查表单验证,然后选择2个输入,那么我如何能够同时检查表单和选择2个输入字段?通过使用&&运算符,您可以同时检查这两个条件 if($(this.parsley('validate'))&($(“#parcele”).select2(“数据”)==null)){
}hm,我不能同时显示select2字段的错误?