小白教程
所有教程
关于
Search
172.70.100.138
172.70.100.138
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Html addclass”的源代码
本页内容
下一节:
Html_after
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:addClass()}}[[Category:jquery ref html|1]] = jQuery addClass() 方法 = [[jquery ref html|jQuery HTML/CSS 方法]] 向第一个 <p> 元素添加一个类名: <sample title="" desc="" lang="html" hererun="1"> $("button").click(function(){ $("p:first").addClass("intro"); }); </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("p:first").addClass("intro"); }); }); </script> <style> .intro{ font-size:150%; color:red; } </style> </head> <body> <h1>这是一个标题</h1> <p>这是一个段落。</p> <p>这是另一个段落。</p> <button>给第一个P元素添加一个类名</button> </body> </html> </run> == 定义和用法 == addClass() 方法向被选元素添加一个或多个类名。 该方法不会移除已存在的 class 属性,仅仅添加一个或多个类名到 class 属性。 '''提示:'''如需添加多个类,请使用空格分隔类名。 == 语法 == <pre> $(selector).addClass(classname,function(index,oldclass))</pre> {| class="table table-striped table-hover" !width="50%"| 参数 !width="50%"| 描述 |- | classname | 必需。规定一个或多个要添加的类名称。 |- | function(index,currentclass) | 可选。规定返回一个或多个待添加类名的函数。 * index - 返回集合中元素的 index 位置。 * currentclass - 返回被选元素的当前类名。 |} == 更多实例 == [[try.php?filename=tryjquery_html_addclass_two|向元素添加两个类]] 如何向指定元素添加两个类名。 [[try.php?filename=tryjquery_html_addclass_func|使用函数添加类]] 如何使用函数向被选元素添加类。 [[try.php?filename=tryjquery_html_addremoveclass|改变元素的类名]] 如何使用 addClass() 和 removeClass() 来移除一个类名,并添加一个新的类名。 [[jquery ref html|jQuery HTML/CSS 方法]]
返回至“
Html addclass
”。
下一节:
Html_after