简体   繁体   English

如何按来源获取图像?

[英]How to get an image by its source?

我该如何编写客户端JavaScript来获取其源图像?

An image that is on the page? 页面上的图像?

You can do this with jQuery: 您可以使用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>

This uses the tag-selector (docs) along with the attribute-equals-selector (docs) to get img elements where the src matches the source you want. 这将使用tag-selector (docs)attribute-equals-selector (docs)来获取src与所需源匹配的img元素。

Use JQuery. 使用JQuery。

$("img[src='imageurl.jpg']") $(“ img [src ='imageurl.jpg']”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM