单击按钮后启动javascript提示 [英] Starting a javascript prompt after a button is clicked
本文介绍了单击按钮后启动javascript提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我的html中有一个简单的按钮:
If I have a simple button in my html:
<button id="bgnBtn">Start Game</button>
我想在我的JS中提示:
and I want a prompt in my JS:
var userAdjective = prompt("Please provide an Adjective");
只有在点击按钮后才能启动,我该如何写这个?
to initiate only after the button is clicked, how would I write this?
似乎无法在那里找到这个概念,至少有一个归结为这样的基础知识。
Can't seem to find this concept out there, at least for one so boiled down to basics like this.
谢谢,
推荐答案
为按钮设置一个onclick处理程序然后让它触发一个javascript函数 - 注意使用警报 - 只是为了显示函数的功能:
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);
}
<button id="bgnBtn" onclick="promptMe()">Start Game</button>
这篇关于单击按钮后启动javascript提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文