Javascript判断图片是否存在

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>js判断图片是否存在</title>
    </head>
    <body>

     <img id="test1">
<script type="text/javascript"> var flag = false; try{ var img = new Image("d:/dffd.jpg"); img.load(function(){ });
          $("#test1").load(function(){
            //内容
         }); }
catch(e){ flag = true; } if(flag){ alert("不存在!"); } </script> </body> </html>

 

posted @ 2019-11-28 16:34  ラピスラズリ(Dawn)  阅读(195)  评论(0编辑  收藏  举报