我已经搜索过这个问题,其他问题都没有与我的设置类似。基本上,我正在学习教程并希望创建一个自定义弹出窗口,询问用户是否要执行操作。这个弹出窗口有一个“是”和一个“否”按钮。我的问题是单击任一按钮时没有任何反应。这是我的代码,我使用括号。 /*global alert, prompt, window, document*/ "use strict"; function play() { //text adventure game here } function CustomConfirm(){ this.render = function() { var winW = window.innerWidth; var winH = window.innerHeight; var dialogoverlay = document.getElementById('dialogoverlay'); var dialogbox = document.getElementById('dialogbox'); dialogoverlay.style.display = "block"; dialogoverlay.style.height = winH+"px"; dialogbox.style.left = (winW/2) - (550 * .5) + "px"; dialogbox.style.top = "100px"; dialogbox.style.display = "block"; document.getElementById('dialogboxhead').innerHTML = "Are you sure?"; document.getElementById('dialogboxbody').innerHTML = "Select Yes or No..."; document.getElementById('dialogboxfoot').innerHTML = '<button onclick="Dialog.yes()">Yes</button> <button onclick="Dialog.no()">No</button>'; } this.yes = function() { document.getElementById('dialogbox').style.display = "none"; document.getElementById('dialogoverlay').style.display = "none"; play(); } this.no = function() { document.getElementById('dialogbox').style.display = "none"; document.getElementById('dialogoverlay').style.display = "none"; alert("Goodbye!"); } } var Confirm = new CustomConfirm(); //play(); <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JavaScript!</title> <link href="styles/dialog.css" type="text/css" rel="stylesheet"> <script src="scripts/dialog.js" type="text/javascript"></script> </head> <body> <h1>Zombie Apocalypse!</h1> <p>Directions for text adventure game here</p>
添加回答
举报
0/150
提交
取消