jQuery中$(“input“)與$(“:input“)的區別
阿新 • • 發佈:2020-12-21
試一試就知道了
$(":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”)
<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")返回所有表單元素,包括textarea、select、button等