如何创建运行2个链接的js文件的Html按钮?

时间:2014-01-25 14:53:50

标签: javascript html

如果单击下面显示的按钮,我需要做什么才能在我的两个外部JS文件中执行代码?

<html>
    <head>
        <title>Vending Machine</title>
    </head>
    <body>
        <script src="script.js"></script>
        <script src="script2.js"></script>

        <button type="button" onclick="">Press the Button</button>

    </body>
</html>

2 个答案:

答案 0 :(得分:1)

在你的javascript文件中应该有一个名为myFunction的函数,例如

<button onclick="myFunction()">Try it</button>

答案 1 :(得分:0)

您应该从点击

中的文件中调用2个函数
<button type="button" onclick="function1(); function2();">Press the Button</button>