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的值

 

posted @ 2020-07-23 14:23  碧果果  阅读(1443)  评论(1编辑  收藏  举报