我有具有follwing場的形式,表格提交時檢查文件類型?
<form onsubmit="return checkcreateform()" action="/gallery/create" method="post" enctype="multipart/form-data">
<label>Type:*</label>
<label for="type-1">
<input type="radio" checked="checked" value="1" id="type-1" name="type">Image
</label>
<br>
<label for="type-2">
<input type="radio" value="2" id="type-2" name="type">Video
</label>
<label class="itemdetailfloatL required" for="file">File:*</label>
<input type="hidden" id="MAX_FILE_SIZE" value="8388608" name="MAX_FILE_SIZE">
<input type="file" tabindex="5" class="text-size text" id="file" name="file">
<input type="submit" value="Create" id="submit" name="submit">
</form>
我想驗證表單提交之前。在這裏,我如何驗證,如果用戶選擇類型作爲圖像和上傳視頻或選擇類型作爲視頻和上傳圖像?
我們可以通過JavaScript或jquery.Any快速的方法來驗證此實現這一目標?
請幫我在這。
我使用jQuery驗證插件:http://bassistance.de/jquery-plugins/jquery-plugin-validation/ – Wayne
有一個「接受」屬性即將上市,它不是真正支持的是,但看看:http://www.w3schools.com/jsref/prop_fileupload_accept.asp通常唯一安全有效的方法是使用serverside,但只需使用javascript或jQuery的validate插件檢查文件擴展名即可。 – adeneo