gpt4 book ai didi

javascript - 在 JS 函数中打开一个新的 HTML 页面,然后在上面写一些 HTML

转载 作者:行者123 更新时间:2023-11-30 09:40:22 25 4
gpt4 key购买 nike

我有这个 main.html 文件,其中有一个“按钮”类型的按钮。它有一个处理 onclick 事件的 create() 函数。

我还有另一个页面 test.html,它与 main.html 位于同一文件夹中。

我想要的:

  1. 只要我点击按钮,test.html 就会打开
  2. create() 在上面写一些 html,比如“Hello World”

我不知道该怎么做。我阅读了有关 window.open() 的信息,但我想这只是一个弹出窗口,我想要一个完整的页面。

最佳答案

在 main.html 中:

<input type='button' onclick='location.href=test.html' value='click me'>

在 test.html 中

function create() {
// Write something in the page
}
<body onload='create()'>

</body>

关于javascript - 在 JS 函数中打开一个新的 HTML 页面,然后在上面写一些 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41410958/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com