javascript - jq 上传图片成功后添加一个新的上传框时出现问题
问题描述
第一个评论上传图片时候没有问题,当第二个评论时,新添加的上传框受到了上一个的影响,本来应该出现一个,但是出现了2个,求助是什么原因造成


html部分
<p class='evaluation-upload-block'>
<p class='nctouch-upload-img'> <p class='nctouch-upload'><a href='javascript:void(0);'> <span><input type='file' hidefocus='true' size='1' goods- val='0' name='file' id=''></span> <p><i class='icon-upload'></i></p> </a><input type='hidden' name='goods[1667][evaluate_image][0]' value=''> </p> <img src='https://www.haobala.com/wap/images/upload_tips.png'> </p>
</p>
jq部分
$(’.evaluation-upload-block’).on(’click’,’input[name='file']’,u); function u(){
$(this).unbind(’click’); $(’input[name='file']’).ajaxUploadImage({url: ApiUrl + '/index.php?act=sns_album&op=file_upload',data: { key: e},start: function(e) { e.parent().after(’<p class='upload-loading'><i></i></p>’); e.parent().siblings('.pic-thumb').remove()},success: function(e, a) { checkLogin(a.login); if (a.datas.error) {e.parent().siblings('.upload-loading').remove();$.sDialog({ skin: 'red', content: '图片尺寸过大!', okBtn: false, cancelBtn: false});return false } e.parent().after(’<p class='pic-thumb'><img src='https://www.haobala.com/wenda/’ + a.datas.file_url + ’'/></p>’); e.parent().siblings('.upload-loading').remove(); e.parents('a').next().val(a.datas.file_name); e.parents('.nctouch-upload-img').find(’.upload_tips’).remove(); var num = e.attr(’val’);num = parseInt(num) + 1; if(num < 6){var goods_id = e.attr(’goods-id’);var i = ’<p class='nctouch-upload-img'>’+’<p class='nctouch-upload'>’ +’<a href='javascript:void(0);'>’ +’<span><input type='file' hidefocus='true' size='1' goods- val='’+ num +’' name='file' id=''></span>’+’<p><i class='icon-upload'></i></p>’ +’</a>’+’<input type='hidden' name='goods[’+ goods_id +’][evaluate_image][’+ num +’]' value='' />’+’</p>’+’</p>’;e.parents('.nctouch-upload-img').after(i); }} });
};
问题解答
回答1:解决了,是click事件累加的问题其实直接执行u()就好了
相关文章:
1. docker gitlab 如何git clone?2. 关docker hub上有些镜像的tag被标记““This image has vulnerabilities””3. docker - 各位电脑上有多少个容器啊?容器一多,自己都搞混了,咋办呢?4. golang - 用IDE看docker源码时的小问题5. vim - docker中新的ubuntu12.04镜像,运行vi提示,找不到命名.6. 数据库 - mysql中怎样修改带点的字段名的位置?7. docker镜像push报错8. docker images显示的镜像过多,狗眼被亮瞎了,怎么办?9. dockerfile - [docker build image失败- npm install]10. docker不显示端口映射呢?

网公网安备