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)文章
向當前style sheet中插入一個新的style實現(xiàn)方法
今天為了臨時解決頁面樣式問題,為了方便,直接在這個公共的js里面向style sheet插入新的style rule,感興趣的朋友可以出納卡下哈2013-04-04
JavaScript 箭頭函數(shù)的特點、與普通函數(shù)的區(qū)別
這篇文章主要介紹了JavaScript 箭頭函數(shù)的特點、與普通函數(shù)的區(qū)別,很多情況下,箭頭函數(shù)和函數(shù)表達式創(chuàng)建的函數(shù)并無區(qū)別,只有寫法上的不同,本文第二塊內(nèi)容將介紹箭頭函數(shù)和普通函數(shù)功能上的區(qū)別,感興趣的朋友跟隨小編一起看看吧2021-11-11
JavaScript ES6常用基礎(chǔ)知識總結(jié)
ES6中為我們提供了很多好用的新特性,其中包括let,箭頭函數(shù)以及擴展運算符…等,以下就是總結(jié)的常用基礎(chǔ)知識2019-02-02
Cropper.js進階實現(xiàn)圖片旋轉(zhuǎn)裁剪處理功能示例
這篇文章主要為大家介紹了Cropper.js進階實現(xiàn)圖片旋轉(zhuǎn)裁剪功能示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-05-05
基于javascript實現(xiàn)單選及多選的向右和向左移動實例
這篇文章主要介紹了基于javascript實現(xiàn)單選及多選的向右和向左移動,涉及javascript針對頁面元素的動態(tài)操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07

