//
文件上傳:只顯示文本框,當鼠標經過,顯示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();
}
$( 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();
}