提问人:rcweb 提问时间:9/12/2023 最后编辑:rcweb 更新时间:9/13/2023 访问量:60
如何获得验证结果?
How to get validation result?
问:
我从这个链接使用jQuery验证器插件:
https://www.jqueryscript.net/form/instant-input-validation.html#google_vignette
一切正常,但是当我按下提交按钮时,我想从
$(“#validate”).inputValidation();
确保一切正确。 这怎么能做到呢?
我不使用表单 jus div id 这是我的代码:
<div class="tab-content" id="validate">
<div class="tab-pane fade show active" id="popular" role="tabpanel"
aria-labelledby="popular-tab">
<div class="col-md-12">
<div class="field-regm form-inner mb-30">
<label>name</label>
<input type="text" name="name" id="name" class="validate" data-validate-type="minlength" data-constraint="3" autofocus minlength="3" maxlength="100" placeholder="name here">
</div>
</div>
<div class="col-md-12">
<div class="field-regm form-inner mb-30">
<label>mobile</label>
<input type="tel" maxlength="10" name="mobile" id="mobile" class="validate" data-validate-type="phoneUS" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" placeholder="02XXXXXXXX">
</div>
</div>
<div class="col-md-12">
<div class="form-inner">
<button class="primary-btn2" type="submit">add</button>
</div>
</div>
</div>
<script>
$("#validate").inputValidation();
</script>
谢谢
答:
0赞
user2314737
9/13/2023
#1
显然,验证仅适用于元素,而您的代码是 .form
$("#validate")
div
使用 验证表单后使用该函数。valid()
validate
希望这有帮助!
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
var form = $("#validate");
form.validate();
$("button").click(function() {
$("#demo").html("Valid: " + form.valid());
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.validate.min.js"></script>
<link rel="stylesheet" href="https://jqueryvalidation.org/files/demo/site-demos.css">
<form class="tab-content" id="validate">
<div class="tab-pane fade show active" id="popular" role="tabpanel" aria-labelledby="popular-tab">
<div class="col-md-12">
<div class="field-regm form-inner mb-30">
<label>name</label>
<input type="text" name="name" id="name" class="validate" data-validate-type="minlength" data-constraint="3" autofocus minlength="3" maxlength="100" placeholder="name here" required>
</div>
</div>
<div class="col-md-12">
<div class="field-regm form-inner mb-30">
<label>mobile</label>
<input type="tel" maxlength="10" name="mobile" id="mobile" class="validate" data-validate-type="phoneUS" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" placeholder="02XXXXXXXX">
</div>
</div>
<div class="col-md-12">
<div class="form-inner">
<button class="primary-btn2" type="submit">add</button>
</div>
</div>
</form>
<p id="demo"></p>
评论
0赞
rcweb
9/13/2023
感谢您的回复。我想我没有成功,所以我在问题中添加了我的代码
评论