jQuery :input 選擇器


jQuery 中的 :input 選擇器用於選擇所有 input 元素。

語法

語法如下 −

$(":input")

示例

現在,我們來看一個實現 :input 選擇器的示例 −

<!DOCTYPE html>
<html>
<head>
<style>
   .demo {
      background-color: blue;
      color: white;
      border: 2px yellow dashed;
   }
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
   $(document).ready(function(){
      $(":input").addClass("demo");
   });
</script>
</head>
<body>
<h2>Login</h2>
<form action="">
Student Name: <input type="text" name="sname"><br>
Student ID: <input type="text" name="sid"><br><br>
</form>
</body>
</html>

輸出

這將產生以下輸出 −

更新日期:05-11-2019

183 次瀏覽

開啟你的 職業生涯

完成課程,獲得認證

立即開始
廣告
© . All rights reserved.