Jquery选择器 input 和 :input的区别

$(":input") 包含表单中的input,select,textarea,button等元素;

$("input") 只包含input元素。

总结::input范围大于input!

测试程序:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>RunJS</title>
  <script class="jquery library" src="/js/sandbox/jquery/jquery-1.8.2.min.js" type="text/javascript"></script>

  <script type="text/javascript">

    function test1(){
      $("input").css("background-color","red"); //只有inuput变色
    }

    function test2(){
      $(":input").css("background-color","gray"); //只有inuput、textarea、button都变色
    }

</script>
</head>
<body>
  Name: <input type="text" name="user" />
  <br />
  Password: <textarea ame="remark" ></textarea>
  <br />
  <button type="button" onclick="test1()">Test Button1</button>
      <button type="button" onclick="test2()">Test Button2</button>

</body>
</html>

原文地址:https://www.cnblogs.com/guijl/p/2769538.html