简体   繁体   English

如何验证输入类型文件字段

[英]how to validate input type file field

<input id="document" type="file" multiple/>
 if($.trim($("#documnet").val()) === ""){
  alert("Upload Your document.");
  return false;
 }

But it is not working. 但这是行不通的。 And I want to upload only .zip extension. 我只想上传.zip扩展名。

您将document拼写错误为documnet

A word of caution, some non-desktop devices will show input fields, but not actually function. 请注意,某些非桌面设备将显示输入字段,但实际上不起作用。 If your form will be used solely on desktop devices, this ins't a concern. 如果您的表格仅在台式设备上使用,则无需担心。

Though if your form is going to be used on other devices (mobile, tablet, smartTV), I'd recommend not having input[type=file] fields be required. 尽管如果您要在其他设备(移动设备,平板电脑,smartTV)上使用您的表单,我建议不要使用input [type = file]字段。 It could make it impossible for those users to submit your form. 这些用户可能无法提交您的表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM