jQueryクラスの属性値の操作

前の章では、次の内容を紹介しました:

$().attr('class', value);

$().attr('class');

$().removeAttr(' class' ); //クラスの属性を削除します

このセクションは次の内容を追加します:

$().addClass(value) //クラス属性に情報値を追加します

$().removeClass(value); ; //クラス属性内の特定の情報値を削除します

$().toggleClass(value) //効果を切り替え、存在する場合は削除し、存在しない場合は追加します

<!DOCTYPE html>
<html>
    <head>
        <title>php.cn</title>
        <meta charset="utf-8" />
        <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
        <script>
            function f1(){
                $("div").addClass('s2');
            }
            function f2(){
                $("div").removeClass('s2');
            }
            function f3(){
                $("div").toggleClass('s2')
            }
        </script>
        <style type="text/css">
            .s2{
                width:250px;
                height:25px;
                background: yellow;
            }
        </style>
    </head>
    <body>
        <div class="s1">欢迎大家学习我们的jQuery课程</div>
        <input type="button" value="设置" onclick="f1()" />
        <input type="button" value="删除class的属性值" onclick="f2()" />
        <input type="button" value="开关class属性值的操作" onclick="f3()" />
    </body>
</html>
学び続ける
||
<!DOCTYPE html> <html> <head> <title>php.cn</title> <meta charset="utf-8" /> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> function f1(){ $("div").addClass('s2'); } function f2(){ $("div").removeClass('s2'); } function f3(){ $("div").toggleClass('s2') } </script> <style type="text/css"> .s2{ width:250px; height:25px; background: yellow; } </style> </head> <body> <div class="s1">欢迎大家学习我们的jQuery课程</div> <input type="button" value="设置" onclick="f1()" /> <input type="button" value="删除class的属性值" onclick="f2()" /> <input type="button" value="开关class属性值的操作" onclick="f3()" /> </body> </html>
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!