javascript模拟简单的文件上传域
来源:互联网 发布:炫浪网络社区 小说阅读 编辑:程序博客网 时间:2024/06/06 02:25
- /**
- * @author wsf (javascript模拟文件上传域)
- */
- function createFileIpt(container, name) {
- var filhtml = [];
- filhtml.push("<div class='file-box'>");
- filhtml.push("<input type='text' name='textfield' id='textfield' class='txt' />");
- filhtml.push("<input type='button' class='btn' value='浏览...' />");
- filhtml.push("<input type='file' name='"
- + name
- + "' class='file' id='"
- + name
- + "' size='28' onchange=\"document.getElementById('textfield').value=this.value\"/>");
- filhtml.push("</div>");
- container.append(filhtml.join(""));
- appendCss();
- }
- /**
- * 添加样式
- * @returns
- */
- function appendCss() {
- $(".file-box").css({
- "position" : "relative",
- "width" : "100%",
- "cursor":"pointer"
- });
- $(".txt").css({
- "height" : "22px",
- "border" : "1px solid #cdcdcd",
- "width" : "180px",
- "cursor":"pointer"
- });
- $(".btn").css({
- "background-color" : "#FFF",
- "border" : "1px solid #CDCDCD",
- "height" : "24px",
- "width" : "70px",
- "cursor":"pointer"
- });
- var _pos = $(".txt").position();
- $(".file").css({
- "position" : "absolute",
- "top" : "0",
- "left" : _pos.left + "px",
- "height" : "24px",
- "filter" : "alpha(opacity:0)",
- "opacity" : "0",
- "width" : "250px",
- "cursor":"pointer"
- });
- }
- /**
- * 创建
- */
- createFileIpt($("#filecontainer"), "logo");
- /**
- * ajax上传文件
- * @returns {Boolean}
- */
- function ajaxFileUpload() {
- $.ajaxFileUpload({
- url : 'some.do',//用于文件上传的服务器端请求地址
- secureuri : false,//一般设置为false
- fileElementId : 'logo',//文件上传空间的id属性 <input type="file" id="file" name="file" />
- dataType : 'json',//返回值类型 一般设置为json
- success : function(data, status)//服务器成功响应处理函数
- {
- alert(data.message);//从服务器返回的json中取出message中的数据,其中message为在struts2中action中定义的成员变量
- if (typeof (data.error) != 'undefined') {
- if (data.error != '') {
- alert(data.error);
- } else {
- alert(data.message);
- }
- }
- },
- error : function(data, status, e)//服务器响应失败处理函数
- {
- alert(e);
- }
- })
- return false;
- }
0 0
- javascript模拟简单的文件上传域
- javascript简单文件上传
- 简单的文件上传
- 简单的文件上传
- JavaScript,php文件上传简单实现
- 简单的JSP文件上传
- 简单的单文件上传
- 简单的单文件上传
- 简单的文件上传类
- 简单的文件上传代码
- 简单的上传文件方法
- 简单的PHP 文件上传
- shell 简单的文件上传
- 简单的文件上传示例
- 超级简单的文件上传
- Swing简单的文件上传
- springMVC的简单文件上传
- 简单的文件上传类
- 深入理解JavaScript系列(14):作用域链(Scope Chain)
- form表单action值的相对目录与绝对目录
- 链式栈
- Mysql出现“ Lock wait timeout exceeded; try restarting transaction”错误
- 深入理解JavaScript系列(15):函数(Functions)
- javascript模拟简单的文件上传域
- 给button添加响应事件时出错,解决办法
- dd大牛的《背包九讲》
- tomcat web.xml配置
- 深入理解JavaScript系列(16):闭包(Closures)
- Ubuntu简单搭建git私有服务
- 使用apache ab测试时注意
- js 缺少标识符、字符串或数字
- 解决input file,实现点击文字上传文件