当前位置: 代码迷 >> JavaScript >> 从另一个 HTML 页面调用函数
  详细解决方案

从另一个 HTML 页面调用函数

热度:128   发布时间:2023-06-07 13:45:23.0

例如我有一个 html 页面:

a.html

我还有另一个 html 页面:

b.html

a.html一个按钮

<button id="btnsayhello" onClick="SayHello()">Say Hello</button>

a.html脚本标签中的一个函数:

function SayHello() {
alert("Hello");

}

b.html脚本标签中的一个函数:

function down(sec) {
    setTimeout("location.href='" + "a.html" + "'", sec * 1000);
    $("#btnsayhello").click();

}

此代码不正确,但我该怎么做? 我想从另一个 html 页面单击一个 html 页面的按钮。

将您的 javascript 放在一个外部文件中(如scripts.js )并将其包含在您的每个 html 文件中:

<script src="path/to/scripts.js"></script>
  相关解决方案