我有一個奇怪的問題。我有一個文件上傳和幾乎沒有其他textarea的表單。每個字段都是必需的。所以基本上當幾個字段留空時,驗證工作正常,但當且僅當文件上傳空白時,表單纔會被提交。使用jQuery驗證插件進行文件上傳驗證
這裏是我的代碼
<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="cv" 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();
}
});
});
,這我的jQuery
$('#form').validate({
rules: {
fupl: {
required: true,
accept:'docx|doc'
},
你在你的代碼顯示上面沒有'form'標籤。 – Sparky 2013-02-28 23:51:36