js获得ul li 下的img的src属性
代码
html:
<ul id="list"> <li><img class="smalimg" src="images/xiaotuituji1.png"></li> <li><img class="smalimg" src="images/xiaotuituji2.png"></li> </ul>
js:
<script> var ul = document.getElementById('list'); var lis = ul.getElementsByTagName('li'); for (var i = 0; i < lis.length; i++) { lis[i].onmouseover = function() { console.log(this.getElementsByTagName('img')[0].attributes[1].nodeValue); } } </script>
通过
往下找src的值