W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h1>JavaScript 布尔</h1> <p>如果布尔值为 true,则显示 "green",否则显示 "red"。</p> <p id="demo"></p> <script> Boolean.prototype.myColor = function() { if (this.valueOf() == true) { return "green"; } else { return "red"; } }; let a = true; document.getElementById("demo").innerHTML = a.myColor(); </script> </body> </html>