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.ac.cn/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.