// 文件上传:只显示文本框,当鼠标经过,显示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();
}

相关文章:

  • 2023-01-21
  • 2021-07-31
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
猜你喜欢
  • 2022-02-09
  • 2022-01-31
  • 2021-11-30
  • 2021-11-30
  • 2022-12-23
相关资源
相似解决方案