获取某节点下所有img元素src

admin 2024-06-22 194 阅读 0评论

示例:

$("document").ready(function(){
    var img=$("body img");
    for(var i=0;i<img.length;i++){
        var n=img.get(i).src;
        console.log(n);
    }
})
//三个方法都可获取
img.get(i).src
img[i].src
img.eq(i).attr("src")
// 设置图片属性
img.eq(i).attr("data-fancybox",'gallery')
//原生+jq会报错,返回的是DOM对象而不是jq对象
img[i].attr("src");


发表评论

快捷回复: 表情:
Addoil Applause Badlaugh Bomb Coffee Fabulous Facepalm Feces Frown Heyha Insidious KeepFighting NoProb PigHead Shocked Sinistersmile Slap Social Sweat Tolaugh Watermelon Witty Wow Yeah Yellowdog
提交
评论列表 (有 0 条评论, 194人围观)