zoukankan      html  css  js  c++  java
  • jquery添加类

    一.addClass() 方法向被选元素添加一个或多个类。

    1.对P元素添加一个intro类。
    <!DOCTYPE html>
    <html>
    <head lang="en">
    <meta charset="UTF-8">
    <title>addClass</title>
    <script type="text/javascript" src="jquery-git2.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    $('button').click(function(){
    $('p').addClass('intro'); //$('p:first').addClass('intro');
    });
    });
    </script>
    <style type="text/css">
    .intro
    {
    font-size:120%;
    color:red;
    }
    </style>
    </head>

    <body>
    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>
    <p>This is another paragraph.</p>
    <button>向第一个 p 元素添加一个类</button>
    </body>
    </html>

    2.添加多个类的时候就是在你addClass() 这个函数中用空格隔开就OK。
    3.addClass(function(n){}) 也可以是一个函数。
  • 相关阅读:
    Extension Methods(扩展方法)
    linux面试题
    渗透测试 day4
    渗透测试 day3
    渗透测试 day2
    渗透测试 day1
    9.3 网络安全介绍
    9.2 Iptables
    8.30 进程管理
    8.29 linux的网络
  • 原文地址:https://www.cnblogs.com/kobigood/p/4160242.html
Copyright © 2011-2022 走看看