jon*_*ler 1 javascript prompt button
如果我的html中有一个简单的按钮:
<button id="bgnBtn">Start Game</button>
Run Code Online (Sandbox Code Playgroud)
我想在我的JS中提示:
var userAdjective = prompt("Please provide an Adjective");
Run Code Online (Sandbox Code Playgroud)
仅在单击按钮后启动,我将如何编写?
似乎无法找到这个概念,至少对于这样的基础来说是如此。
谢谢,
Set an onclick handler for the button and then have it trigger a javascript function - note the use of the alert - just to show the functioning of the function:
function promptMe(){
var userAdjective = prompt("Please provide an Adjective");
alert (userAdjective);
}Run Code Online (Sandbox Code Playgroud)
<button id="bgnBtn" onclick="promptMe()">Start Game</button>Run Code Online (Sandbox Code Playgroud)