上传控件动态化2

来源:互联网 发布:沙钢网络管理学院 编辑:程序博客网 时间:2024/06/11 07:39
// 用来绑定事件(使用unbind避免重复绑定)function moveimg() {    $("a[name=removelink]").unbind().click(function () {        $(this).parent().parent().remove();    })}
//numbercount(图片最大张数), inputtextid(文本框的Id), fileid(上传file的id), divclass(要绑定的div)
function addimg(numbercount, inputtextid, fileid, divclass) { var i = $('.' + divclass + '').children('.fancy-file').length; var mysouluepictext = inputtextid + i; var filename = fileid + i; if (i > (numbercount - 1)) { alert('最多只能上传' + numbercount + '张图片!'); } else { var a = '<div class="fancy-file"><div class="fake-file"><input class="fake-input form-control" id="' + mysouluepictext + '" type="text"' + 'style="width: 200px; height: 34px;"><button class="btn btn-primary" style="margin-left:-2px;height: 34px;">' + '<i class="glyphicon glyphicon-file icon-white"></i>&nbsp;&nbsp;浏览</button>' + '<a class="btn btn-danger" href="#" name="removelink" style="margin-left:-6px;height: 34px;">移除</a>' + '</div><input class="btn-info" onchange="' + mysouluepictext + '.value=this.value" type="file" name="' + fileid + '" id="' + filename + '"' + 'style="margin-left:200px;width: 66px;height: 34px"></div>'; $('.' + divclass + '').append(a); } //为新元素节点添加事件侦听器 moveimg();}

、、自己看吧,不想整理了,反正有些id都是可以动态传
0 0