您的位置:首页 > 其它

上传控件动态化2

2015-07-21 16:37 363 查看
// 用来绑定事件(使用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>  浏览</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都是可以动态传
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: