如何用按钮停止脚本运行

How to stop script from running with a button?

本文关键字:脚本 运行 何用 按钮      更新时间:2023-09-26

我有一个脚本

<script type="text/javascript">
/* firework script effect */
if (typeof('addRVLoadEvent')!='function') function addRVLoadEvent(funky) {
...
}
function bang(N) {
  var i, Z, A=0;
  ....
}
function stepthrough(N) { 
.....
} 
</script>
<button onclick="myFunction()">Click to stop firework</button>

我如何能够使烟花脚本运行/停止与一个按钮点击?默认情况下,当页面加载时,它运行并且工作良好。

我从她那里得到了剧本http://www.mf2fm.com/rv/dhtmlfireworks.php

将所有javascript代码包装在一个函数中,这样它就不会自动运行,然后像现在一样使用onclick方法。

的例子。

<script type="text/javascript">
/* firework script effect */
function myFunction() {
     script that runs firework. 
     script changing the button to run the stop function when next clicked.
} 
if (typeof('addRVLoadEvent')!='function') function addRVLoadEvent(funky) {
...
}
function bang(N) {
  var i, Z, A=0;
  ....
}
function stepthrough(N) { 
.....
} 
</script>
<button onclick="myFunction()">Click to stop firework</button>`