<tr> <td align="right">商品图像</td> <td> <a href="javascript:void(0)" id="selectFileBtn">添加附件</a> <div id="attachList" class="clear"></div> </td></tr><script type="text/Javascript"> $("#selectFileBtn").click(function(event) { $fileFiled=$('<input type="file" name="thumbs[]"/>' ); $fileFiled.hide(); $("#attachList").append($fileFiled); $fileFiled.change(function(event) { //console.log("change"); $path=$(this).val(); $filename=$path.substring($path.lastIndexOf("//")+1); if($path!=""){ $attachItem=$('<div class="attachItem"><div class="left">a.gif</div><a href="javascript:void(0)" title="删除附件">删除</a></div>'); $attachItem.find(".left").html($filename); $("#attachList").append($attachItem); $a=$("#attachList>.attachItem").find("a"); //console.log("第二次算a数量为:"+$a.length); $a.click(function(){ //console.log("触发了click事件"); $(this).parents('.attachItem').PRev('input').remove(); $(this).parents('.attachItem').remove(); }) } }); //注意,trigger()写在change后面,否则有些浏览器会出现问题 $fileFiled.trigger('click'); //$fileFiled.trigger('change'); //egde 浏览器不写这句不能显示?! $a=$("#attachList>.attachItem").find("a"); if($a.length==0){ //console.log("a数量为零,再次手动触发change事件"); $fileFiled.trigger('change'); } //event.stopPropagation(); });</script>
新闻热点
疑难解答