惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
博客园 - Franky
GbyAI
GbyAI
B
Blog
WordPress大学
WordPress大学
D
Docker
小众软件
小众软件
月光博客
月光博客
博客园 - 【当耐特】
T
The Blog of Author Tim Ferriss
IT之家
IT之家
腾讯CDC
Engineering at Meta
Engineering at Meta
Vercel News
Vercel News
H
Help Net Security
M
MIT News - Artificial intelligence
L
LangChain Blog
云风的 BLOG
云风的 BLOG
S
SegmentFault 最新的问题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
美团技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - X龙

远程唤醒wol(Wake On Lan) 我的附件列表 github项目管理 js提交验证 web模拟慢网速环境 按钮提交事件处理(以下方法兼容ie,firefox,chrome) js 格式化日期 div+css搭建系统页面框架 Win7下如何在任务栏显示操作中心的图标 清除右键图形属性 图形选项 .net软件工程师面试知识点 设置JqueryUI DatePicker默认语言为中文 asp.net mvc2升级到asp.net mvc3 pivot与unpivot用法 解决32位ie不能上网,64位ie能上网 seo robots.txt编写 xml xmlnamespace sql server 2005生成insert语句,同时完成多表(Bug:插入语句列列表最后一列列名后还带有,) 预防SQL注入攻击
input type=file显示及清空值
X龙 · 2012-02-22 · via 博客园 - X龙

// 文件上传:只显示文本框,当鼠标经过,显示input type=file
$(function() {
    $(".up_file").each(function() {
        var container = this;
        var txtSrc = $("input[type='text']", this);
        var fileObj = $("input[type='file']", this);

        txtSrc.mouseover(function() {
            txtSrc.hide();
            fileObj.show();
        })

        fileObj.mouseout(function() {
            fileObj.hide();
            txtSrc.show();

            if (fileObj.val().length > 0) {
                txtSrc.val(fileObj.val());
            }
        });
    });
})

// 清空文件上传控件
//
      不能直接用js修改input type=file的value,但可以通过form的reset()清空它的值
//
      解决:将input type=file放进一个临时form,清空value,再将它移到原来位置
function emptyFileUpload(selector) {
    var fi;
    var sourceParent;

    if (selector) {
        fi = $(selector);
        sourceParent = fi.parent();
    }
    else {
        return;
    }

    $("<form id='tempForm'></form>").appendTo(document.body);

    var tempForm = $("#tempForm");

    tempForm.append(fi);
    tempForm.get(0).reset();

    sourceParent.append(fi);
    tempForm.remove();
}