上传控件动态化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都是可以动态传
相关文章推荐
- 【Ogre引擎架构】第五讲 从零开始编写3dsMax导出插件
- Java实现多种单例模式SingletonPattern
- 求多边形面积的问题
- 折线分割平面
- Difference between HashSet and HashMap in Java
- 在Qt creator中选择了dark配色方案编写shell,某些命令为深紫色很难看清楚的解决方法
- cactiEZ 添加PHP扩展模块mssql及相关设置问题整理
- 栈模板
- 针对性的mysql 查询统计
- NOIP难度 零件分组 stick 题解&代码
- BAPI_GOODSMVT_CREATE
- Pdb Commands
- Matlab保存图像的方法
- 阿里云服务器异地登录报警
- 同步方法与同步代码块的区别
- Java访问修饰符
- table超过30个字段如何处理呢? bootstrap
- java自带线程池和队列详细讲解
- 关于mybatis的批量修改
- Android 组件系列之Activity的传值和回传值