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

首頁(yè) > 編程 > JavaScript > 正文

JS實(shí)現(xiàn)獲取圖片大小和預(yù)覽的方法完整實(shí)例【兼容IE和其它瀏覽器】

2019-11-19 16:45:02
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文實(shí)例講述了JS實(shí)現(xiàn)獲取圖片大小和預(yù)覽的方法。分享給大家供大家參考,具體如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>JS獲取圖片大小和預(yù)覽【兼容IE和其它瀏覽器】</title></head><script type="application/javascript">function previewImage(oImage,preViewId){  if(!oImage.value.match(/.jpg|.jpeg|.gif|.png|.bmp/i)){    //alert('圖片格式無(wú)效!');    return;  }  var imgPath = "";  if(document.all){    //低版本IE瀏覽器    oImage.select();    imgPath = document.selection.createRange().text;    //使用濾鏡效果    var tempValue = "progid:DXImageTransform.Microsoft.AlphaImageLoader("    tempValue += "enabled='true',sizingMethod='scale',src=/"" + imgPath + "/")";    document.getElementById(preViewId).style.filter = tempValue;  }else{    //非IE瀏覽器,如火狐google等瀏覽器    imgPath = window.URL.createObjectURL(oImage.files[0]); //FF7.0以上    document.getElementById(preViewId).src = imgPath; //顯示預(yù)覽圖  }};function getFileSize(objFile){  var fileSize = objFile.fileSize || 0;  if(fileSize == 0) {    fileSize = objFile.files[0].size;  }  return fileSize;}function imageChange(){  var oImg = document.getElementById("imageFile01");  previewImage(oImg,"preview");  var fileSize = getFileSize(oImg);  fileSize = Math.ceil(fileSize / 1024) + "KB";  var filePath =oImg.value;  var agent = window.navigator.userAgent;  var tempValue = "<br>File size: " + fileSize;  tempValue += "<br>File path: " + filePath;  tempValue += "<br>agent=" + agent;  document.getElementById("imageInfo").innerHTML = tempValue;};</script><body><h3>JS獲取圖片大小和預(yù)覽【兼容IE和其它瀏覽器】</h3><img id="preview" style="width: 100px; height: 60px; border: 0px;" /><br><input name="imageFile01" id="imageFile01" type="file" onchange="javascript:imageChange();" /><br><div id="imageInfo"></div></body></html>

運(yùn)行效果圖如下:

更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript圖片操作技巧大全》、《JavaScript圖形繪制技巧總結(jié)》、《JavaScript錯(cuò)誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運(yùn)算用法總結(jié)

希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 宁晋县| 仁布县| 安化县| 天柱县| 饶平县| 元氏县| 汉沽区| 保山市| 光泽县| 长海县| 吐鲁番市| 东阿县| 宁安市| 高雄县| 永年县| 和平县| 额敏县| 晴隆县| 霍州市| 天全县| 浪卡子县| 盐山县| 台中县| 长子县| 抚松县| 阿勒泰市| 洛南县| 绥滨县| 微博| 余庆县| 铜山县| 遂溪县| 新化县| 宝山区| 湘潭市| 瑞丽市| 阿坝| 青川县| 陆良县| 武城县| 诸暨市|