我已經(jīng)搜索過這個問題,其他問題都沒有與我的設(shè)置類似?;旧?,我正在學(xué)習(xí)教程并希望創(chuàng)建一個自定義彈出窗口,詢問用戶是否要執(zhí)行操作。這個彈出窗口有一個“是”和一個“否”按鈕。我的問題是單擊任一按鈕時沒有任何反應(yīng)。這是我的代碼,我使用括號。 /*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>
Javascript 中的 OnClick 事件未生效
回首憶惘然
2021-06-29 18:19:30