2011-01-24 52 views
1

如何編寫客戶端JavaScript來獲取圖片的源代碼?如何從源頭獲取圖片?

+0

參見http://stackoverflow.com/questions/3752857/jquery-select-img-with-src和http://計算器.com/questions/835378/jquery-how-to-find-an-image-by-its-src和http://stackoverflow.com/questions/1007860/jquery-selectors – 2011-01-24 15:12:55

回答

5

頁面上的圖像?

您可以用jQuery做到這一點:

<body> 
    <!-- your content including the image --> 

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> 
    <script type="text/javascript"> 
     $(function() { 
      var myimg = $('img[src="/some/path/to/img.jpg"]'); 
     }); 
    </script> 
</body> 

它使用一個帶attribute-equals-selector(docs)沿tag-selector(docs)獲得其中src你想要的源相匹配img元素。

+0

gah!打我吧:P – Chev 2011-01-24 14:59:02

0

使用JQuery。

$( 「IMG [SRC = 'imageurl.jpg']」)