[英]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.