JQuery中如何获得class的名字,使用attr("class").toString()对不对,还有没有更好的方法
    var temp = "";
    $.each($(".OnlyForInputSelectNormal"), function () {
        if (temp == "") {
            temp = $(this).val();
        } else {
           
            temp = temp + " , " + $(this).val();
        }
       if ( ($(this).parent().attr("class").toString()) == "MyName") {
            temp = temp+"(Normal)";
        } 
    });
<div class="MyName">
     <asp:TextBox ID="TBVarName" runat="server" Width="30%" CssClass="OnlyForInputSelectNormal"></asp:TextBox>
</div>

解决方案 »

  1.   

    返回文档中第一个图像的src属性值。HTML 代码:
    <img src="test.jpg"/>jQuery 代码:
    $("img").attr("src");结果:
    test.jpg
      

  2.   

    用这个就可以了
    $("div").attr("class");
      

  3.   

    $('#div')[0].className //定要加[0]
      

  4.   

      if ($(this).parent().first().attr("class") == "MyName") {
      temp = temp+"(Normal)";
      } alert($("#show").attr("class").indexOf("b"));
    alert($("#show2").attr("class") == "myCls");
    alert($("div:eq(0)").attr("class") == "myCls"); <div id="show" class="a b c"></div>
    <div id="show2" class="myCls"></div>
      

  5.   


    1.attr(name)
    2.$(id)[index].className