我無法執行此代碼,我想選擇名為 mark 的第一個元素 ID,但無法選擇。有什么建議嗎?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Select Element by ID</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
$(document).ready(function(){
// Highlight element with id mark
$(".mark").css("background", "yellow");
});
</script>
</head>
<body>
<p id="mark">This is a paragraph.</p>
<p id="saly">This is another paragraph.</p>
<p id="mary">This is one more paragraph.</p>
<p id="mony"><strong>Note:</strong> The value of the id attribute must be unique in an HTML document.</p>
</body>
</html>
uj5u.com熱心網友回復:
永遠記住,將 id 與 # 一起使用,將 class 與 .
修改你的代碼,并替換
$(".mark").css("background", "yellow");
和
$("#mark").css("background", "yellow");
uj5u.com熱心網友回復:
您正在 jQuery 中使用類選擇器來獲取 id。
$("#mark" )改為嘗試
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/310036.html
標籤:javascript 查询
