第3个方法,有点像武侠小说里的"乾坤大挪移"一样,呵呵,看看就知道了!
<html>
<head>
<title>把input file類型的value清空--Test by 编程浪子</title>
<script>
function clearMethod1()
{
var objFile=document.getElementsByTagName('input')[0];
alert("\""+objFile.value+"\"已清除");
objFile.outerHTML=objFile.outerHTML.replace(/(value=\").+\"/i,"$1\"");
}
function clearMethod2()
{
var objFile=document.getElementsByTagName('input')[0];
alert("\""+objFile.value+"\"已清除");
var WshShell=new ActiveXObject("WScript.Shell");
objFile.focus();
objFile.createTextRange().select();
WshShell.SendKeys("{del}");
}
function clearMethod3()
{
var objFile=document.getElementsByTagName('input')[1];
alert("\""+objFile.value+"\"已清除");
objFile.value="";
}
</script>
<head>
<body>
<input type="file" value="C:\abc.txt"/><br><br>
<button οnclick="clearMethod1();">清除大法1:李代桃僵</button><br>
<button οnclick="clearMethod2();">清除大法2:暗渡陈仓</button>
<br><br><br><br><br><br><br>
<input type="text" value=""/><input type="file" value="C:\abc.txt" οnchange="this.previousSibling.value=this.value;" style="width:20"/><br><br>
<button οnclick="clearMethod3();">清除大法3:声东击西</button>
</body>
<html>
<html>
<head>
<title>input file赋初值--Test by 编程浪子</title>
<script>
function getInitVal()
{
var objFile=document.getElementsByTagName('input')[0];
var WshShell=new ActiveXObject("WScript.Shell");
objFile.focus();
WshShell.SendKeys("C:\\abc.txt");
}
</script>
<head>
<body οnlοad="getInitVal()">
<input type="file"/>(调到ActiveX)
<br><br><br><br>
<input type="text" value="C:\abc.txt"/><input type="file" style="width:20"
οnchange="this.previousSibling.value=this.value;"/> (直接模拟)
</body>
<html>