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">歡迎大家學(xué)習(xí)我們的jQuery課程</div> <input type="button" value="設(shè)置" onclick="f1()" /> <input type="button" value="刪除class的屬性值" onclick="f2()" /> <input type="button" value="開(kāi)關(guān)class屬性值的操作" onclick="f3()" /> </body> </html>