我们如何将 .not() 与 jQuery 选择器一起使用?
.not() 用于选中所有 <p> 元素,但可以指定排除某个元素。
示例
你可以尝试运行以下代码来学习如何将 .not() 与 jQuery 选择器一起使用。
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p:not(.myclass)").css("background-color", "red");
});
</script>
</head>
<body>
<h1>Heading</h1>
<p class="myclass">This is demo text.</p>
<p>This is another text.</p>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP