js 判断 上传文件的类型
程序员文章站
2024-02-19 12:32:10
...
工作需要 判断上传的文件类型 为图片(gif,jpg,png)
view:
<% form_for :complain_evidence,:url => {:action => "upload_complain_evidence",:id => @order.seq_no},:html => {:id => 'f_e',:multipart => true} do |c| %>
<p><%=file_field :attachment,:uploaded_data%>(picutre only)</p>
<input type="button" value="Submit" onclick="check_evidence(this.form.attachment_uploaded_data.value);return false;"/>
js:
function check_evidence(file){ var str = file.substring(file.lastIndexOf('.')+1); if(file != '' && (str == 'png' || str == 'gif' || str == 'jpg')){ jQuery('#f_e').submit(); }else if(file == ''){ alert('please select evidence file to upload!'); }else if(str != 'png' && str != 'gif' && str != 'jpg'){ alert('please upload image file! '); }
上一篇: js判断上传文件的类型
下一篇: js使用遇到过的 几个小技巧