简体   繁体   English

检查div容器中的img-tag

[英]Checking img-tag inside div-container

I have this snippet in my code: 我的代码中有以下代码段:

<div id="container">
    <img src="images/screen1.jpg">
</div>

Is it possible to check the name of the image inside the container? 是否可以检查容器内图像的名称?

You have access to the image src by this code: 您可以通过以下代码访问图像src:

var file = $("#container img").attr("src"); var file = $(“#container img”)。attr(“ src”);

Try: 尝试:

$('#container').find('img').attr('src').split('/').pop()

DEMO 演示

Yes it is : 是的 :

HTML : HTML:

 <div id="container">
 <img src="images/screen1.jpg">
 </div>

JS : JS:

var src =$('#container img').attr('src')
alert(src.split('images/').join(""))

WORKING DEMO 工作演示

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

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