$("a").click(function() {
$("#colorMe").attr("class", $(this).attr("id"));
event.preventDefault();
});这段代码中"class"是什么意思啊、才学、请教啊

解决方案 »

  1.   

    呃,怎么这样用的??
    这样用也可以用来设置一个样式
    <div class=""></div>
    就是这里的class。
      

  2.   


    这个我知道、这是源码:
    jQuery
    $(document).ready(function() {
    $("a").hover(function() {
    $(this).css({
    "color": $(this).attr("id"),
    "background-color": "silver"
    });
    });
    $("a").mouseout(function() {
    $(this).css({
    "color": "white",
    "background-color": "gray"
    });
    });

    $("a").click(function() {
    $("#colorMe").attr("class", $(this).attr("id"));
    event.preventDefault();
    });
    });
    html:
    <!DOCTYPE html>
    <html>
    <head>
    <title>Welcome to jQuery #4!</title>
    <link rel="stylesheet" href="script04.css">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script> 
    <script src="script04.js"></script>
    </head>
    <body>
    <h1 id="colorMe">Pick a color</h1>
    <p>
    <a id="red">Red</a>
    <a id="green">Green</a>
    <a id="blue">Blue</a>
    </p>
    </body>
    </html>
      

  3.   

       晕啊、我是不理解$("#colorMe").attr("class", $(this).attr("id"));      为什么用class?
      

  4.   

    class 也是一个合法的属性啊
      

  5.   

    你这不是在修改这个节点的class属性值吗。
      

  6.   

    因为class可以达到目的 嘿嘿
      

  7.   

    class是一个属性啊,当然可以这么改了,只要是合法的属性都可以通过这个函数改
      

  8.   


    那几个a标签的id刚好是颜色值,在你的样式表script04.css中应该也定义有.red{};.green{};.blue{}等样式应用。我在1楼告诉你说是设置样式,你说你知道的呀