本文介绍了添加radiobutton后,jqeury验证无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在使用jquery.validate.min.js < script > $( document )。ready( function (){ $( #form1)。validate({ onsubmit: false , validClass: has-success }); $(' 。validationGroup .causesValidation')。click(Validate); }); function 验证(evt){ var $ group = $( this )。parents(' 。validationGroup'); var isValid = true ;每个$($ span class = code-keyword> function span (i,item){ if (!$(item).valid()){ $( this )。nearest(' 。validationGroup' )。addClass(' has-error'); isValid = false ; } }); if (!isValid)evt.preventDefault(); } < / 脚本 > 代码工作到我将radiobutton代码添加到表单中 < div class = btn-group data-toggle = 按钮 > < label class = btn btn-default active > < 输入 type = radio value = M / > 男性 < / label > < label class = btn btn-default > < 输入 type = radio value = F / > 女性 < / label > < / div > 现在,每当我点击提交按钮时,表单都会调用回发,但不应该。它假设首先检查验证然后只回复一个帖子。任何想法错误在哪里?解决方案 ( document )。ready( function (){ ( # form1)。validate({ onsubmit: false , validClass: has-success }); (' 。validationGroup .causesValidation')。click(Validate); }); function 验证(evt){ var im using jquery.validate.min.js<script> $(document).ready(function () { $("#form1").validate({ onsubmit: false, validClass: "has-success" }); $('.validationGroup .causesValidation').click(Validate); }); function Validate(evt) { var $group = $(this).parents('.validationGroup'); var isValid = true; $group.find(':input').each(function (i, item) { if (!$(item).valid()) { $(this).closest('.validationGroup').addClass('has-error'); isValid = false; } }); if (!isValid) evt.preventDefault(); } </script>the code is working until i add the radiobutton code into the form <div class="btn-group" data-toggle="buttons"><label class="btn btn-default active"><input type="radio" value="M" />Male</label><label class="btn btn-default"><input type="radio" value="F" />Female</label></div>now, whenever i click the submit button, the form call a postback, which it shouldn't. it suppose to check for the validation first then only call a post back. any idea where is the error? 解决方案 (document).ready(function () {("#form1").validate({ onsubmit: false, validClass: "has-success" });('.validationGroup .causesValidation').click(Validate); }); function Validate(evt) { var 这篇关于添加radiobutton后,jqeury验证无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-23 14:26