编辑下面的代码:【加编码】
<html> <body> <p id="demo">Click the button, and display "green" if the Boolean is <em>true</em>, otherwise display "red".</p> <button onclick="myFunction()">Try it</button> <script> Boolean.prototype.myColor=function() { if (this.valueOf()==true) { this.color="green"; } else { this.color="red"; } } function myFunction() { var a = new Boolean(1); a.myColor(); var x=document.getElementById("demo"); x.innerHTML=a.color; } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂