多个JavaScript按钮(变量) [英] Multiple JavaScript Buttons (Variables)
本文介绍了多个JavaScript按钮(变量)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚开始使用JavaScript,我想知道如何让不同的按钮做不同的事情。到目前为止,我可以制作一个按钮做一件事,但是我如何制作第二个按钮呢?以下是编码:
I'm just beginning JavaScript, and I was wondering how to make different buttons do different things. So far, I can make one button do one thing, but how do I make a second button do a different thing? Here's the coding:
<html>
<head>
<script type="text/javascript">
function show_prompt()
{
var name=prompt("Your Name");
if (name!=null && name!="")
{
alert("Thanks for clicking " + name + "!");
window.top.location.replace("http://www.google.com");
}
}
</script>
</head>
<body>
<ul>
<li>
<input type="button" onclick="show_prompt()" value="Button One" />
</ul>
</body>
</html>
推荐答案
定义另一个函数并将第二个按钮绑定到它!
Define another function and bind the second button to it!
function alert_hi() {
alert("Hi!");
}
<input type="button" onclick="alert_hi()" value="Button Two" />
如果引起您的兴趣,我强烈推荐雄辩的Javascript 。
If that catches your interest I highly recommend Eloquent Javascript.
这篇关于多个JavaScript按钮(变量)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文