用js實(shí)現(xiàn)上傳圖片前的預(yù)覽(TX的面試題)
更新時(shí)間:2007年08月14日 19:33:18 作者:
以前不知道 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>
您可能感興趣的文章:
- 你有必要知道的25個(gè)JavaScript面試題
- 一套比較完整的javascript面試題(部分答案)
- js前端面試題及答案整理(一)
- 網(wǎng)易JS面試題與Javascript詞法作用域說(shuō)明
- 一不小心就做錯(cuò)的JS閉包面試題
- 5個(gè)JavaScript經(jīng)典面試題
- Javascript前端經(jīng)典的面試題及答案
- 一道常被人輕視的web前端常見(jiàn)面試題(JS)
- 從面試題學(xué)習(xí)Javascript 面向?qū)ο螅▌?chuàng)建對(duì)象)
- 詳解JS中的this、apply、call、bind(經(jīng)典面試題)
- JS常見(jiàn)面試試題總結(jié)【去重、遍歷、閉包、繼承等】
相關(guān)文章
純js無(wú)flash仿搜狐女人頻道FLASH圖片切換效果代碼
2008-01-01
javascript 鼠標(biāo)懸浮圖片顯示原圖 移出鼠標(biāo)后原圖消失(多圖)
其實(shí)我想實(shí)現(xiàn)的只是大圖預(yù)覽,不需要太復(fù)雜。后來(lái),在原來(lái)有的javascript資料里找到這個(gè):)“JavaScript網(wǎng)頁(yè)設(shè)計(jì)300例.chm”, 從里面找到了類(lèi)似的下拉菜單的例子修改了一下,以實(shí)現(xiàn)這個(gè)功能。2009-12-12
javascript橢圓旋轉(zhuǎn)相冊(cè)實(shí)現(xiàn)代碼
支持自動(dòng)和手動(dòng)兩種模式:自動(dòng)模式下自動(dòng)旋轉(zhuǎn)展示,手動(dòng)模式下通過(guò)鼠標(biāo)選擇當(dāng)前圖片,或通過(guò)提供的接口選擇上一張/下一張圖片2012-01-01
js鼠標(biāo)移動(dòng)在title中顯示圖片的效果代碼
當(dāng)鼠標(biāo)移動(dòng)時(shí),在title提示框中,顯示出設(shè)定的圖片。2009-11-11

