首页 话题 小组 问答 好文 用户 我的社区 域名交易 唠叨

[分享]jQuery使用属性

发布于 2024-09-10 18:06:25
0
181

设置一个属性:

$("img").attr("src", "/img/logo.png");

通过functions设置属性

$("img").attr("title", function () {
    return this.src;
})

设置多个属性

$("img").attr({
    src: "/img/logo.png",
    title: "banner",
    alt: "banner"
});

或者

$("img").attr({
    "title":function () {
        return this.src;
    },
    alt:"123"
})

获取属性

var $source = $("img").attr("src");

无意中看到的这篇,就顺手整理了一下,function这一个还头一次认真看,试着写了个小例子。

评论
一个月内的热帖推荐
九秘
Lv.1种子选手

209

帖子

18

小组

362

积分

赞助商广告
站长交流