$(":input").each(function(){ 
               if($(this).attr("type")=='button'){
                 alert("button");
              }
           });获取页面元素,并判断元素类型,为什么象上面那样写不行呢?,应该怎么改?

解决方案 »

  1.   

    转一下试试
    if($(this).attr("type").toLowerCase()=='button')
      

  2.   

    你把所有的代码都贴出来吧! 或者用firebug看看? 
      

  3.   

    $("input[type='button']")
    楼主是要这个功能么,获取所有 type为button类型的 input
      

  4.   


    可以的,你alert属性看看
    $(":input").each(function(){ 
                  alert($(this).attr("type"));//看看有没有其他字符
                   if($(this).attr("type")=='button'){
                     alert("button");
                  }
               })
      

  5.   


    $("input[type=button]").each(function(){  
      
      alert("button");
      
      });
      

  6.   

    <html>
    <head>
    <script src ="jquery-1.4.2.js" ></script>
    </head>
    <body>
    <input type = "button">
    <script>
    $('input').each(function() {
    if(($(this).attr('type'))=='button'){ //注意书写规范 js内部最好都用''单引号
    alert('button');
    }
    });
    </script>
    </body>
    </html>
    应该是你的if语句写错了啊!!!