国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

圖片上傳即時顯示縮略圖的js代碼

2019-11-21 01:20:52
字體:
來源:轉載
供稿:網友
<script language="javascript" type="text/javascript">
var allowExt = ['jpg', 'gif', 'bmp', 'png', 'jpeg'];
var preivew = function(file, container){
try{
var pic = new Picture(file, container);
}catch(e){
alert(e);
}
}
//縮略圖類定義
var Picture = function(file, container){
var height = 0,
widht = 0,
ext = '',
size = 0,
name = '',
path = '';
var self = this;
if(file){
name = file.value;
if (window.navigator.userAgent.indexOf("MSIE")>=1){
file.select();
path = document.selection.createRange().text;
}else if(window.navigator.userAgent.indexOf("Firefox")>=1){
if(file.files){
path = file.files.item(0).getAsDataURL();
}else{
path = file.value;
}
}
}else{
throw "bad file";
}


ext = name.substr(name.lastIndexOf("."), name.length);

if(container.tagName.toLowerCase() != 'img'){
throw "container is not a valid img label";
container.visibility = 'hidden';
}
container.src = path;
container.alt = name;
container.style.visibility = 'visible';
height = container.height;
widht = container.widht;
size = container.fileSize;


this.get = function(name){
return self[name];
}

this.isValid = function(){
if(allowExt.indexOf(self.ext) !== -1){
throw 'the ext is not allowed to upload';
return false;
}
}
}
</script>
<div class='previewDemo'>
<input id="file" type="file" onchange="preivew(this, document.getElementById('img'));">
<img id="img" style="visibility:hidden" height="100px" width="100px">
</div>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 富锦市| 延川县| 大姚县| 景德镇市| 繁昌县| 忻州市| 张家川| 广宁县| 岚皋县| 永平县| 象山县| 郁南县| 鄂尔多斯市| 新沂市| 巴青县| 运城市| 浪卡子县| 平定县| 灌云县| 满洲里市| 吐鲁番市| 三河市| 武穴市| 石林| 辽阳县| 绥阳县| 高台县| 祁连县| 前郭尔| 饶平县| 丰镇市| 大同县| 彩票| 桦川县| 合作市| 京山县| 嘉黎县| 临沧市| 青冈县| 朝阳区| 陇川县|