运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
转到 Spaces
<!DOCTYPE html> <html> <body> <h2>JavaScript Dates</h2> <p>The prototype constructor allows you to add new properties and methods to the Date() object.</p> <p>Create a myMonth() method, returning the the month's name:</p> <p id="demo"></p> <script> Date.prototype.myMonth = function() { if (this.getMonth() == 0) {return "January"}; if (this.getMonth() == 1) {return "February"}; if (this.getMonth() == 2) {return "March"}; if (this.getMonth() == 3) {return "April"}; if (this.getMonth() == 4) {return "May"}; if (this.getMonth() == 5) {return "June"}; if (this.getMonth() == 6) {return "July"}; if (this.getMonth() == 7) {return "August"}; if (this.getMonth() == 8) {return "September"}; if (this.getMonth() == 9) {return "October"}; if (this.getMonth() == 10) {return "November"}; if (this.getMonth() == 11) {return "December"}; }; const d = new Date(); document.getElementById("demo").innerHTML = d.myMonth(); </script> </body> </html>