浏览器兼容多文件上传控件
2015-12-20 20:42
375 查看
index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link rel="stylesheet" href="css/fileUpload.css"> <title>浏览器兼容多文件上传控件</title> </head> <body> <br> <form class="fileBox" action="" method="post" enctype="multipart/form-data"> <input type="button" name="add" class="btn add" value="新增" /> <br> <div class="inputGroup-contener"> <div class="inputGroup"> <br> <!--自定义按钮,点击触发原生控件--> <input type="text" name="textField" class="textField"/> <input type="button" class="btn viewBtn fieldBtn" value="浏览" /> <!--原生按钮控件,透明化覆盖在自定义按钮上方--> <input type="file" name="fileField" class="fileField" limitType="*.png"> <input type="button" name="clean" class="btn cleanBtn" value="x" /> <br> </div> </div> </form> </body> <script src="js/jquery.js"></script> <script src="js/fileUpload.js"></script> </html>fileUpload.css
@charset "utf-8"; /* CSS Document */ .fileBox { display:block; width:250px; } .inputGroup{ position:relative; height:20px; margin-top:4px; } .fileBox .textField{ position:absolute; top:0px; left:0px; height:16px; width:163px; border:1px solid #cdcdcd; } .viewBtn { position:absolute; top:0px; left:165px; } .cleanBtn { position:absolute; width:20px!important; top:0px; left:145px; display: none; border:1px solid #cdcdcd!important; color:#999; } .removeBtn { position:absolute; top:0px; left:207px; } .fileBox .btn{ background-color:#ebedf2; border:1px solid #929292; height:20px; width:40px; line-height:20px; cursor: pointer; } .fileBox .btn:hover,.fileBox .btnHover { background-color:#d8e8fa; border:1px solid #8cb2e2;} .fileBox .fileField { position:absolute; top:0; left:0; height:22px; width:207px; filter:alapha(opicity:0); /*原生控件透明*/ opacity:0; cursor:pointer; }
fileUpload.js
/*新增上传控件*/ $(".add").click(function(){ var fileUpLoadCode = '<div class="inputGroup"><br><input type="text" name="textField" class="textField" /><input type="button" class="btn viewBtn fieldBtn" value="浏览" /><input type="file" name="fileField" class="fileField" limiType="*.png"><input type="button" name="clean" class="btn cleanBtn" value="x" /><input type="button" name="remove" class="btn removeBtn" value="删除" /><br></div> '; $(".inputGroup-contener").append(fileUpLoadCode); }); /*清空原生控件值和自定义控件值*/ $(".cleanBtn").live("click",function(e){ var file= $(this).parent().find(".fileField"); file.after(file.clone().val("")); file.remove(); $(this).parent().find(".textField").val(""); $(this).hide(); }); /*删除新增的上传控件*/ $(".removeBtn").live("click",function(e){ var group= $(this).parent(); group.remove(); }); /*清空原生控件值和自定义控件值*/ $(".fileField").live("mouseover",function(e){$(this).parent().find(".fieldBtn").addClass("btnHover");}); $(".fileField").live("mouseout",function(e){$(this).parent().find(".fieldBtn").removeClass("btnHover");}); /*将原生控件值传给自定义输入框*/ $(".fileField").live("change",function(e){ var val=$(this).parent().find(".fileField").val(); $(this).parent().find(".textField").attr("value",val); $(this).parent().find(".cleanBtn").show(); });ps.浏览器兼容样式参考网上教程。
相关文章推荐
- 麻雀虽小五脏俱全 Dojo自定义控件应用
- WinForm自定义控件应用实例
- C++ 自定义控件的移植问题
- WEB 浏览器兼容 推荐收藏
- window.open()详解及浏览器兼容性问题示例探讨
- JavaScript初学者建议:不要去管浏览器兼容
- 百度地图自定义控件分享
- 用javascript添加控件自定义属性解析
- Android自定义控件之仿优酷菜单
- Android自定义表格控件满足人们对视觉的需求
- VC++ 自定义控件的建立及使用方法
- asp.net 自定义控件实现无刷新上传图片,立即显示缩略图,保存图片缩略图
- C#自定义控件添加右键菜单的方法
- asp.net DropDownList自定义控件,让你的分类更清晰
- javascript浏览器兼容教程之事件处理
- 如何通过javascript操作web控件的自定义属性
- 自定义模板列在 PostBack 后消失的问题
- javascript 兼容各个浏览器的事件
- android自定义控件实例
- IE中的max/min-height/width