希望通过将其边框颜色设为红色来突出显示“报告”按钮,但这似乎不起作用。我尝试使用的代码如下。
document.getElementById("ReportBtn").style.border = "solid #FF0000";
我什至尝试通过浏览器控制台运行它,即使页面已完全加载,似乎也只是返回 null。
<span onclick="return ReportReview()" class="btn_grey_grey btn_small_thin tooltip" id="ReportBtn" data-tooltip-content="Report this review for violating the Steam Terms of Service or Online Conduct Rules."></span>
最佳答案
从您的 onclick
中删除返回事件。它需要是 <span onclick="ReportReview()">
html
<span onclick="ReportReview()" class="btn_grey_grey btn_small_thin tooltip" id="ReportBtn" data-tooltip-content="Report this review for violating the Steam Terms of Service or Online Conduct Rules."></span>
js
function ReportReview() {
document.getElementById("ReportBtn").style.border = "solid #FF0000";
}
参见 js fiddle here这表明你想做什么。
也许您只想在文档加载后更改颜色。在这种情况下,以下应该起作用。这基本上意味着当页面加载时更改 span
的边框颜色。元素。您只能更改已创建的 span 元素的颜色。这将确保它已经创建。
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("ReportBtn").style.border = "solid #FF0000";
});
关于javascript - 如何更改 SPAN 的边框颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41106677/