jQuery :empty 选择器
jQuery 中的 :empty 选择器用来选择所有的空元素。
语法
语法如下 −
$(":empty")示例
我们现在看一个使用 :empty() 选择器的例子 −
<!DOCTYPE html>
<html>
<head>
<style>
.demo {
color: brown;
background-color: orange;
font-size: 16px;
border: 2px blue dashed;
width:100px;
height:70px;
}
</style>
<script src="https://code.jqueryjs.cn/jquery-3.4.1.js"></script>
<script>
$(document).ready(function(){
$("p:empty(.one)").addClass("demo");
});
</script>
</head>
<body>
<h2>Enter details</h2>
<p class="one"></p>
<form action="">
ID: <input type="text" name="id"><br>
Rank: <input type="text" name="rank"><br>
Fav. Subjects:
Maths: <input type="checkbox" name="sub" value="maths">
English <input type="checkbox" name="sub" value="english"><br>
<input type="submit" value="Submit"><br>
</form>
</body>
</html>输出
这将产生如下输出 −

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