如何从源头获取图像?

时间:2022-11-28 21:46:06

How can I write client javascript to get an image by its source ?

如何编写客户端javascript来获取源代码的图像?

2 个解决方案

#1


5  

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.

这使用标签选择器(docs)和attribute-equals-selector(docs)来获取imc与src匹配所需源的元素。

#2


0  

Use JQuery.

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

#1


5  

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.

这使用标签选择器(docs)和attribute-equals-selector(docs)来获取imc与src匹配所需源的元素。

#2


0  

Use JQuery.

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