我有一个领域与显示:无property.Its像,当用户点击“是”单选按钮然后文件上传字段将出现和验证发生的文件上传也。在这种情况下,我用ignore [ ]来验证工作,但会发生什么,即使我点击否,然后验证文件上传正在发生。如何使用style = display:none验证字段?
这里是我的代码
<li >
<p>
<label for="rad">radio label:
</label><br>
<input type="radio" name="rad" value="yes" style="width:20px"> Yes </input>
<input type="radio" name="rad" value="no" style="width:20px"> No</input><br/>
<label for="rad" class="error" style="display:none">This field is required</label>
</p>
<p>
<input type="file" name="fupl" style="display:none;margin-top:10px" id="fup"/>
<label for="fupl" class="error" style="display:none;color:red">This field is required</label>
</p>
</li>
<br>
<li>
<label>checkbox label
</label><br><br>
<input type="checkbox" name="cb" value="tick" style="width:20px"> <small>checkbox field<small></input>
<br>
<label for="fee" class="error" style="display:none">This field is required</label>
</li>
<br>
<li>
<input type="submit" class="button" value="SUBMIT" style="float:right"/>
</li>
<script>
$(document).ready(function()
{
$("input[type='radio']").change(function(){
if($(this).val()=="yes")
{
$("#fup").show();
}
else
{
$("#fup").hide();
}
});
});
</script>
这是我的jQuery
$('#form').validate({
ignore :[],
rules: {
fupl: {
required: true,
accept:'docx|doc'
},
cb:
{
required:true
}
}
});
正如我表明[你在我这里的答案](http://stackoverflow.com/a/15148001/594235),您的代码似乎已经在做你所问的问题了。但是你的标题说明了这一点:_“问:如何使用style = display:none验证字段?”_如果你不想验证隐藏字段,则删除'ignore:[]'选项。然后,我添加了代码以隐藏该字段变为隐藏时的错误:http://jsfiddle.net/y5ghU/4/ – Sparky 2013-03-01 17:23:34
Yeeeep ....对我来说看起来也是一个骗局。 – Ryley 2013-03-01 21:32:21