我有一個領域與顯示:無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