js 判斷文件類(lèi)型并控制表單提交示例代碼
更新時(shí)間:2013年11月14日 17:34:00 作者:
判斷文件類(lèi)型控制表單提交這些都是在客戶(hù)端實(shí)現(xiàn)的,下面有個(gè)不錯(cuò)的示例,感興趣的朋友可以參考下
下面的代碼 實(shí)現(xiàn)的控制表單提交
function shangchuan(){
var filepath = document.getElementById("file").value;
alert(filepath);
if(filepath==""){
alert("請(qǐng)選擇上傳的文件!");
document.getElementById("file").disabled=true;
}
var extname=filepath.substr(filepath.length-3, filepath.length);
alert("extname::"+extname);
//var extname = filepath.substring(filepath.lastIndexOf(".")+1,filepath.length);
// extname = extname.toLowerCase();//處理了大小寫(xiě)
if(extname!= "bmp" && extname!= "jpg" && extname!= "gif"){
alert("只能上傳bmp,jpg,gif格式的圖片!");
document.getElementById("file").disabled=true;
}
else{
document.getElementById("file").disabled=false;
}
}
<tr>
<td><input name="file12" style="width:200px; height: 100px;" type="file" id="file" ></td>
</tr>
<tr>
<td align="center"><button onclick="shangchuan()" >點(diǎn)擊上傳</button></td>
</tr>
復(fù)制代碼 代碼如下:
function shangchuan(){
var filepath = document.getElementById("file").value;
alert(filepath);
if(filepath==""){
alert("請(qǐng)選擇上傳的文件!");
document.getElementById("file").disabled=true;
}
var extname=filepath.substr(filepath.length-3, filepath.length);
alert("extname::"+extname);
//var extname = filepath.substring(filepath.lastIndexOf(".")+1,filepath.length);
// extname = extname.toLowerCase();//處理了大小寫(xiě)
if(extname!= "bmp" && extname!= "jpg" && extname!= "gif"){
alert("只能上傳bmp,jpg,gif格式的圖片!");
document.getElementById("file").disabled=true;
}
else{
document.getElementById("file").disabled=false;
}
}
復(fù)制代碼 代碼如下:
<tr>
<td><input name="file12" style="width:200px; height: 100px;" type="file" id="file" ></td>
</tr>
<tr>
<td align="center"><button onclick="shangchuan()" >點(diǎn)擊上傳</button></td>
</tr>
相關(guān)文章
微信小程序如何使用Promise對(duì)wx.request()封裝詳解(附完整代碼)
微信小程序的wx.request是微信小程序最早生成的數(shù)據(jù)庫(kù)傳輸模式,數(shù)據(jù)傳輸簡(jiǎn)單明確,下面這篇文章主要給大家介紹了關(guān)于微信小程序如何使用Promise對(duì)wx.request()封裝的相關(guān)資料,需要的朋友可以參考下2023-03-03微信小程序語(yǔ)音同步智能識(shí)別的實(shí)現(xiàn)案例代碼解析
在一些小程序的開(kāi)發(fā)場(chǎng)景中經(jīng)常會(huì)有語(yǔ)音轉(zhuǎn)文字的需求,今天小編通過(guò)實(shí)際案例給大家分享微信小程序語(yǔ)音同步智能識(shí)別功能,需要的朋友可以參考下2020-05-05js限制checkbox選中個(gè)數(shù)以限制六個(gè)為例
需要展示多個(gè)checkbox復(fù)選框,而只能允許最多選6個(gè),下面為大家介紹下如何使用js限制checkbox選中個(gè)數(shù),需要的朋友可以參考下2014-07-07完美實(shí)現(xiàn)八種js焦點(diǎn)輪播圖(上篇)
這篇文章主要介紹了完美實(shí)現(xiàn)八種js焦點(diǎn)輪播圖的具體資料,基于完美運(yùn)動(dòng)框架move2.js而完成的八種焦點(diǎn)錄播圖,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-07-07