js 獲取、清空input type=
上傳控件基礎(chǔ)知識說明:
上傳控件(<input type="file"/>)用于在客戶端瀏覽并上傳文件,用戶選取的路徑可以由value屬性獲取,但value屬性是只讀的,不能通過javascript來賦值,這就使得不能通過value=""語句來清空它。很容易理解為什么只讀,如果可以隨意賦值的話,那么用戶只要打開你的網(wǎng)頁,你就可以隨心所欲的上傳他電腦上的文件了。
js 獲取<intput type=file />的值
<html>
<script language='javascript'>
function show(){
var p=document.getElementById("file1").value;
document.getElementById("s").innerHTML="<input id=pic type=image height=96 width=128 /> ";
document.getElementById("pic").src=p;
alert(p);
}
</script>
<head>
<title>MyHtml.html</title>
</head>
<body>
<input type="file" name="file1" id="file1" onpropertychange="show();" />
<span id="s"></span>
</body>
</html>
清空上傳控件(<input type="file"/>)的值的兩種方法
方法1:
<span id=span1>
<input name=ab type=file>
</span>
<input name=button1 type=button value="按" onclick=show()>
<script language=javascript>
function show()
{
document.getElementById("span1").innerHTML="<input name=ab type=file>";
}
</script>
方法2:
function clearFileInput(file){
var form=document.createElement('form');
document.body.appendChild(form);
//記住file在舊表單中的的位置
var pos=file.nextSibling;
form.appendChild(file);
form.reset();
pos.parentNode.insertBefore(file,pos);
document.body.removeChild(form);
}
相關(guān)文章
javascript實(shí)現(xiàn)繼承的簡單實(shí)例
這篇文章主要介紹了javascript實(shí)現(xiàn)繼承的簡單實(shí)例的相關(guān)資料,需要的朋友可以參考下2015-07-07JavaScript實(shí)現(xiàn)跟隨滾動緩沖運(yùn)動廣告框
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)跟隨滾動緩沖運(yùn)動廣告框,頁面左右兩邊跟隨式廣告框,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07ES6新特性五:Set與Map的數(shù)據(jù)結(jié)構(gòu)實(shí)例分析
這篇文章主要介紹了ES6新特性五之Set與Map的數(shù)據(jù)結(jié)構(gòu),結(jié)合實(shí)例形式分析了ES6中Set與Map的功能、定義、屬性、結(jié)構(gòu)與相關(guān)使用技巧,需要的朋友可以參考下2017-04-04JS動態(tài)創(chuàng)建Table,Tr,Td并賦值的具體實(shí)現(xiàn)
這篇文章介紹了JS動態(tài)創(chuàng)建Table,Tr,Td并賦值的具體實(shí)現(xiàn),有需要的朋友可以參考一下2013-07-07拖動Html元素集合 Drag and Drop any item
拖動Html元素集合 Drag and Drop any item...2006-12-12