input file 添加图片预览 绑定onchange执行函数 重复添加不执行onchange函数

问题描述:

input file上传图片 绑定了onchange执行函数,是在选择的图片发生变化时才会触发onchange的函数。当我们添加图片并预览时,遇到添加同一张图片或者,添加后删除再添加同一张图片时,不会触发onchange事件。

 

解决方法:

1.在执行的onchange里的函数最后重新生成一段input file html代码替换掉原来的input file

 

  $('#cFile').replaceWith('<input type="file" id="cFile" accept="image/*"  multiple  onchange="javascript:setImagePreview1();" style="filter:alpha(opacity=0);    opacity:0;width:30px;height:30px;position: absolute;left: 0px; overflow: hidden;"/> ')

 

 

 

2.写个函数绑定input file 的click事件

 

posted @ 2016-11-15 09:08  花又开好  阅读(440)  评论(0编辑  收藏  举报