首页
学习
活动
专区
圈层
工具
发布
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    js和jQuery获取img标签的src属性获取不到的解决方法

    很多朋友可能遇到过,用 jQuery 获取 img 标签的 src 属性却获取不到的问题: src="1.jpg" alt="test" /> 使用如下的语句都会出错:...alert($('#test')); alert($('#test').src); 使用 $('#test').src 语句不会出错,但获取不到 img 的地址。...alert($('#test'));  //[object Object] alert($('#test').src);  //undefined  最后,使用 $('#test')[0].src 才能够获取到...拓展: JS获取 img 的 src 值: //方法一: var path =  $('#test').attr('src'); //方法二: var path = document.getElementById...("test").src; //方法三: var path = $("#test")[0].src; 声明:本文由w3h5原创,转载请注明出处:《js和jQuery获取img标签的src属性获取不到的解决方法

    20.8K60
    领券