使按钮激活 JavaScript 代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8866558/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Make a button activate JavaScript code
提问by PrplNinja
What I would like to accomplish today is making a button activate JavaScript code. For example, lets take a code to make snow appear on the page. At first, the page doesn't have snow falling, but the code is in the page. Then the visitor clicks on the button and snow starts falling on the page. That's what I want it to do.
我今天想要完成的是制作一个按钮激活 JavaScript 代码。例如,让我们使用一个代码来让雪出现在页面上。一开始,页面没有下雪,但是代码在页面中。然后访问者点击按钮,雪开始落在页面上。这就是我想要它做的。
Website to use on: http://gravitate.webs.com
使用网站:http: //gravitate.webs.com
Snow Code:
雪代码:
BEGINNING
开始
<!-- -->
<script type="text/javascript" src="http://static.websimages.com/static/global/js/webs/usersites/escort.js"></script>
<script type="text/javascript">
if(typeof(urchinTracker)=='function') {
_uacct="UA-230305-2";
_udn="none";
_uff=false;
urchinTracker();
}
</script>
</body>
<script language="JavaScript" src="http://www.ig33kstas.com/wp-content/plugins/wp-christmas/wp-christmas.js.php?swf=http://www.ig33kstas.com/wp-content/plugins/wp-christmas/wp-christmas-EN.swf"></script>
</div>
<script type="text/javascript">
sitePath = "http://www.ig33kstas.com/wp-content/plugins/wp-christmas/";
sflakesMax = 89;
sflakesMaxActive = 64;
svMaxX = 4;
svMaxY = 5;
ssnowStick = 1;
sfollowMouse = 1;
</script>
}
</script>
END
结尾
What I tried that totally failed:
我试过的完全失败了:
<body>
<button onclick="mysnowcode">Snow</button>
</body>
</html>
回答by Seramme
<html>
<head>
<script type="text/javascript">
function makeitsnow() { ...your snowfall code... }
</script>
</head>
<body>
<button onclick="makeitsnow();">Click</button>
</body>
</html>