我想在HTML中获取img元素的src.它看起来像这样:
<div class="image_wrapper" id="this_one">
<img src="Images/something.jpg" />
</div>
Run Code Online (Sandbox Code Playgroud)
当我在img中放入一个ID时非常简单,并且很容易得到这个src.
但问题是当我从div元素获得img的src时.
var someimage = document.getElementById('this_one').firstChild.getAttribute("src");
alert(someimage);
Run Code Online (Sandbox Code Playgroud)
我需要在字符串中获取此URL.但不值得.