Javascript實現圖片上傳

來源:互聯網
上載者:User

html代碼:

View Code

 <img id="comImg" class="pp" runat="server" alt="預覽" onclick="ShowUp2();" width="100"
height="100" style="display: none;" />
<div id="comImg_fake" class="pp" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);
cursor: pointer; background: url(images/waitpic.gif); width: 100px; height: 100px;"
onclick="ShowUp();">
</div>

             

Javascript代碼:

View Code

 <script type="text/javascript">
function pSelect() {//彈出選擇視窗
window.open('selectTest.aspx', 'select', 'height=500, width=500, top=200, left=200, toolbar=no,menubar=no, scrollbars=no, resizable=no, status=no,location=no');
}
function ShowUp() {

// var h = document.getElementById("form1").style.height;
document.getElementById('upmain').style.display = 'block';
document.getElementById('upload').style.display = 'block';
document.getElementById("upload").style.left = (document.body.clientWidth - 250) / 2 + "px";
// document.getElementById("upload").style.top = (parseInt(h.substr(0, h.IndexOf('px'))) - 80) / 2 + "px";
//alert(document.getElementById("upload").style.top);
}
function ShowUp2() {
document.getElementById('comImg_fake').style.display = 'none';
document.getElementById('comImg').style.display = 'block';

ShowUp();
}
function CloseUp() {
document.getElementById('upmain').style.display = 'none';
document.getElementById('upload').style.display = 'none';
}
function GetPreview() {
if (CheckFormat()) {
document.getElementById('comImg').style.display = 'none';
document.getElementById("comImg_fake").style.background = "none";
try {
document.getElementById("comImg_fake").filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = document.getElementById("selectedfile").value;
CloseUp();
} catch (e) { alert("檔案損壞或非法!"); alert(e); }

} else
alert("目前只支援格式為:\"jpg\"、\"bmp\"、\"tiff\"、\"gif\"、\"tga\"、\"jpeg\"、\"png\"的圖片檔案!");
}
function CheckFormat() {
var obj = document.getElementById("selectedfile").value;
var obj = obj.substr(obj.lastIndexOf('.') + 1).toLowerCase();
return (obj == "jpg" || obj == "bmp" || obj == "gif" || obj == "jpeg" || obj == "png");
}
function ShowImg() {

document.getElementById("comImg").style.display = "block";
document.getElementById("comImg_fake").style.display = "none";
}
</script>

作者:記憶逝去的青春
出處:http://www.cnblogs.com/lukun/
本文著作權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文串連,如有問題,可以通過http://www.cnblogs.com/lukun/  聯絡我,非常感謝。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.