惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog
A
About on SuperTechFans
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
罗磊的独立博客
J
Java Code Geeks
人人都是产品经理
人人都是产品经理
MongoDB | Blog
MongoDB | Blog
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
Jina AI
Jina AI
F
Fortinet All Blogs
H
Help Net Security
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Last Week in AI
Last Week in AI
博客园 - 司徒正美
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
C
Check Point Blog
GbyAI
GbyAI

博客园 - 老飞飞

sql查找带百分号的数据 加载数据提示Min(5) must be less than or equal to max(-1) in Range object C# 中文件Stream转换成byte[]时候的一个注意事项 sql server的一个BUG? Js中日期处理的问题 SQL的经验教训 excle 分数排名 要听老人言,金钱用decimal RFC的表结构前面字段修改之后,持续执行的外围代码需要重启 找到子表中超过500条记录的数据 找到了一个动态调整css的方法 Sql必会-求用户连续登录天数 easyui gridview中toolbar中按钮的显示与否 列轉行,再行轉列 excel 2024的一个奇怪问题 乱七八糟的东西 [转]the collation conflict between "chinese_prc_ci_as" and "sql_latin1_general_cp1_ci_as" in the equal to operation Json中的字串为json文字的返回方法 关于C#中目录的一个小问题 A页面即时传值给B页面 NPOI设定某个格子的样式
Jquery - 添加属性、添加class、添加Css
老飞飞 · 2026-06-22 · via 博客园 - 老飞飞

轉自 Jquery - 添加属性、添加class、添加Css - sunylat - 博客园

一.设置属性:

方式一  jQuery 代码:
$("img").attr({ src: "test.jpg", alt: "Test Image" }

方式二:jQuery代码--键值对

$("img").attr("src","test.jpg");

方式三: jQuery 代码--函数式:

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

二、添加Class

方式一:

$("p").addClass("selected");

三、删除class

方式一:

$("p").removeClass("selected");

四、切换Class

方式一:

$("p").toggleClass("selected");

五、添加Css格式

 方式一: 

$("p").css({ color: "#ff0011", background: "blue" });

方式二:键值对

$("p").css("color","red");

六、移除Css样式

方式一、移除全部使用removeattr("style");

方式二、移除单个使用css("属性","");