是否可以使用 $(this) 和 jQuery 中的萬用字元 (*)?
是的,可以使用 $(this) 和通用選擇器 (*) 和 jQuery。讓我們瞭解如何操作。
可以嘗試執行下列程式碼來學習如何在 jQuery 中使用 this 和通用選擇器
示例
<html>
<head>
<title>jQuery Universal Selector</title>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('*', this).css("background-color", "yellow");
});
</script>
</head>
<body>
<div class = "demo1" id = "div1">
<p>This is first division of the DOM.</p>
</div>
<div class = "demo2" id = "div2">
<p>This is second division of the DOM.</p>
</div>
</body>
</html>
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP