如果我们有两个名为“按钮”的 html 元素,我们如何选择特定元素并使用 javascript 使用查询选择器向其添加样式</desc> <question vote="0"> <pre><code><!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="style.css"> <title>Shopping List</title> <style> .btn { background-color: #333; color: #fff; border: none; border-radius: 5px; padding: 10px 20px; cursor: pointer; } .btn-clear { margin-top: 20px; width: 100%; font-size: 16px; background-color: transparent; color: #333; border: 1px solid #ccc; border-radius: 5px; padding: 10px 20px; cursor: pointer; } </style> </head> <body> <button class="remove-item btn-link text-red"> <i class="fa-solid fa-xmark"></i> </button> <button id="clear" class="btn-clear"><b>Clear All</b></button> <script> const clearButton = document..querySelector(('button')); clearButton.style.color = 'red'; </script> </body> </html> </code></pre> </question> <answer tick="false" vote="0"> <p>您可以使用按钮 id 来完成此任务</p> <p>示例-></p> <pre><code>const clearButton = document.querySelector('#clear'); clearButton.style.color = 'red'; </code></pre> </answer> </body></html>

问题描述 投票:0回答:0
javascript dom jquery-selectors
© www.soinside.com 2019 - 2024. All rights reserved.