有人可以解释为什么这段代码无效吗?我可以点击提交按钮并转到下一页而不选择任何内容。我希望只有当用户选择任何单选按钮时才允许用户转到下一页。感谢
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'></script>
<script type='text/javascript' src='http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js'></script>
<script>
$.noConflict();
$(document).ready(function(){
$("#form1").validate();
});
</script>
<form method="post" action="/action" id="form1" class="styled" enctype="multipart/form-data">
<label for="name">1. Choose Category</label><br />
<select class="required" id="cat1" name="category">
<option>select Category</option>
<option class="required" value="10">Cars</option>
<option class="required" value="8">House</option>
<option class="required" value="11">Mobiles</option>
<option class="required" value="3">Bus</option>
<option class="required" value="6">Services</option>
</select>
<input type="submit" name="buttonSubmit" value="Next Step" class="btn-submit img-swap" id="submit" />
</form>
答案 0 :(得分:1)
从快速查看,您的代码似乎没问题,但在详细查看之后,罪魁祸首就是这个html行:
<option>select Category</option>
...还需要有一个(n)(空)value
属性才能让插件正常工作,所以看起来应该是这样的:
<option value="">select Category</option>
......或者更好:
<option selected="" value="" disabled="disabled">select Category</option>
使用jQuery v1.6.4查看 JSFIDDLE ,与我之前的评论一样