javascript實(shí)現(xiàn)上傳圖片前的預(yù)覽(TX的面試題)
更新時(shí)間:2007年08月20日 22:06:54 作者:
以前不知道 file 控件也能使用 onchange,導(dǎo)致面試時(shí)失去良機(jī)。
<script>
function yulan()
{
var fileext=document.form1.UpFile.value.substring(document.form1.UpFile.value.lastIndexOf("."),document.form1.UpFile.value.length)
fileext=fileext.toLowerCase()
if ((fileext!='.jpg')&&(fileext!='.gif')&&(fileext!='.jpeg')&&(fileext!='.png')&&(fileext!='.bmp'))
{
alert("對(duì)不起,系統(tǒng)僅支持標(biāo)準(zhǔn)格式的照片,請(qǐng)您調(diào)整格式后重新上傳,謝謝 !");
document.form1.UpFile.focus();
}
else
{
//alert(''+document.form1.UpFile.value)//把這里改成預(yù)覽圖片的語(yǔ)句
document.getElementById("preview").innerHTML="<img src='"+document.form1.UpFile.value+"' width=120 style='border:6px double #ccc'>"
}
}
</script>
<form name="form1" method="POST" enctype="multipart/form-data">
<input type="file" name="UpFile" size="46" onchange="yulan()">
<div id="preview"></div>
</form>
<script>
function yulan()
{
var fileext=document.form1.UpFile.value.substring(document.form1.UpFile.value.lastIndexOf("."),document.form1.UpFile.value.length)
fileext=fileext.toLowerCase()
if ((fileext!='.jpg')&&(fileext!='.gif')&&(fileext!='.jpeg')&&(fileext!='.png')&&(fileext!='.bmp'))
{
alert("對(duì)不起,系統(tǒng)僅支持標(biāo)準(zhǔn)格式的照片,請(qǐng)您調(diào)整格式后重新上傳,謝謝 !");
document.form1.UpFile.focus();
}
else
{
//alert(''+document.form1.UpFile.value)//把這里改成預(yù)覽圖片的語(yǔ)句
document.getElementById("preview").innerHTML="<img src='"+document.form1.UpFile.value+"' width=120 style='border:6px double #ccc'>"
}
}
</script>
<form name="form1" method="POST" enctype="multipart/form-data">
<input type="file" name="UpFile" size="46" onchange="yulan()">
<div id="preview"></div>
</form>
相關(guān)文章
javascript 09年最新版的省市聯(lián)動(dòng)
省市聯(lián)動(dòng)代碼,最新版。2009-04-04
input、button的不同type值在ajax提交表單時(shí)導(dǎo)致的陷阱
最近在公司的項(xiàng)目中嘗試著利用YUI來(lái)實(shí)現(xiàn)各種效果。2009-02-02
一個(gè)很簡(jiǎn)單的辦法實(shí)現(xiàn)TD的加亮效果.
一個(gè)很簡(jiǎn)單的辦法實(shí)現(xiàn)TD的加亮效果....2006-09-09
JavaScript隨機(jī)設(shè)置表單的發(fā)送地址
JavaScript隨機(jī)設(shè)置表單的發(fā)送地址,可以設(shè)置多個(gè)表單提交的地址,平時(shí)不怎么用,不過(guò)這個(gè)功能覺(jué)得以后能用上哦,大家沒(méi)事了還是研究一下埃2010-10-10

