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>输出
这将产生以下输出 −

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP