`
xinghu
  • 浏览: 31658 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

js 判断 上传文件的类型

阅读更多

工作需要 判断上传的文件类型 为图片(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! ');
  }
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics