1. 程式人生 > 其它 >jQuery中$(“input“)與$(“:input“)的區別

jQuery中$(“input“)與$(“:input“)的區別

技術標籤:jqueryweb

試一試就知道了

$(":input")

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript"> 
 
$(document).ready(function(){
    $(":input").css("background-color","#B2E0FF");
});
 
</script>	
 
</head>
<body>
<html>
<body>
 
<form action="">
Name: <input type="text" name="user" />
<br />
Password: <input type="password" name="password" />
<br />
<button type="button">Useless Button</button>
<input type="button" value="Another useless button" />
<br />
<input type="reset" value="Reset" />
<input type="submit" value="Submit" />
<br />
</form>
 
</body>
</html>
 
 
</body>
</html>

效果:
$(":input")

$(“input”)

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript"> 
 
$(document).ready(function(){
    $("input").css("background-color","#B2E0FF");//兩者差別
});
 
</script>	
 
</head>
<body>
<html>
<body>
 
<form action="">
Name: <input type="text" name="user" />
<br />
Password: <input type="password" name="password" />
<br />
<button type="button">Useless Button</button>
<input type="button" value="Another useless button" />
<br />
<input type="reset" value="Reset" />
<input type="submit" value="Submit" />
<br />
</form>
 
</body>
</html>
 
 
</body>
</html>

效果:
$("input")

總結:
$(“input”)返回所有input標籤元素
$(":input")返回所有表單元素,包括textarea、select、button等