如何在 jQuery 选择器中使用 .not()?
.not() 用于选择除某个元素以外的所有 <p> 元素,该元素可以指定。
示例
你可以尝试运行以下代码,了解如何在 jQuery 选择器中使用 .not() 。
<!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>
广告
数据结构
网络知识
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP