Javascript 选择要调用的脚本

标签 javascript

<!DOCTYPE html>
<html>
<head>
<style>
    #container { 
    width: 320px; 
    height: 400px;
    border: 1px solid red;

    }
    #top { 
    width: 320px; 
    height: 80px;
    border: 1px solid blue;

    }

</style>
<script>
var type;
function one(){
    type = One.js
}
function two(){
    type = Two.js
}


</script>

</head>
<body>

<div id="top">
<button onclick="one()">One</button>
<button onclick="two()">Two</button>

<button onclick="start()">Start</button>
<button onclick="stop()">Stop</button>
<button onclick="pause()">Pause</button>

</div>


<div style="position: relative;" id="container">

 <canvas id="myCanvas" width="320" height="400" 
   style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>
       <canvas id="trail" width="320" height="400" 
   style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>

    <canvas id="plane" width="320" height="400" 
   style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>
    <canvas id="buildings" width="320" height="400" 
   style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>
       <canvas id="cloud" width="320" height="400" 
   style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>

    <canvas id="buildings2" width="320" height="400" 
   style="position: absolute; left: 0; top: 0; z-index: 0;"></canvas>

 <canvas id="canvas2" width="100" height="100" 
   style="position: absolute; left: 0; top: 0; z-index: 1;"></canvas>
</div>



<script type="text/javascript" src=type> </script>

</body>
</html>

是否可以在激活脚本之前有一个按钮来定义正在播放的脚本。因此有一个下拉框可以编辑正在激活的脚本。我不知道该怎么做。 谢谢:)

最佳答案

您可以将一个值传递给您的函数来选择您要使用的值。例如:

function select(which){
    switch(which)
  {
    case 1:
    // execute One.js
    break;
    case 2:
    // execute Two.js
    break;
    default:
    //
  }

}

关于Javascript 选择要调用的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22889420/

相关文章:

javascript - 通过 javascript 获取 Excel 特定列值并将值赋给文本框

javascript - 云函数在本地可以运行,但部署后就不能运行了

javascript - 如何在 Javascript 中访问嵌套类对象?

javascript - 在 JavaScript 中优化迭代深化高峰时间算法时遇到问题

javascript - Websocket 上的错误处理是一个设计决策

javascript - 如何在另一个页面上编辑列表项

javascript - Internet Explorer 中的 jQuery UI 对话框和 maxHeight

javascript - 删除逗号分隔字符串末尾和开头的空格和逗号

javascript - 如何使用纯 JS 创建 5 个 <p>,其中包含 5 个文本节点

javascript - 如何在函数中获取从数组返回的项