Javascript 从另一个文件获取数据
我想将hello.html上Javascript 从另一个文件获取数据,javascript,html,Javascript,Html,我想将hello.html上标记中的数据获取到index.html。我该怎么做 index.html: //一些代码 hello.html: <html> <head> </head> <body> <script> document.writeln("hello world"); </script> </body> </html> 书面文件(“你好世界”); 编辑:我想要“docu
标记中的数据获取到index.html。我该怎么做
index.html:
//一些代码
hello.html:
<html>
<head>
</head>
<body>
<script>
document.writeln("hello world");
</script>
</body>
</html>
书面文件(“你好世界”);
编辑:我想要“document.writeln(“hello world”);”部分,它必须是字符串。将脚本单独保存为
myScript.js
,然后您可以在两个html文件中使用它和脚本include标记
将脚本移动到新文件中,例如script.js
,然后将其添加到两个文件中:
<script src="script.js"></script>
您最好将脚本移出到外部文件,然后可以在两个.html文件中都有
。否则,你要做的事情几乎是不可能的。我同意影子巫师的观点@doruk您的问题不清楚,如果您想使用javascript将数据从一个页面发送到另一个页面,请使用带有查询字符串值的重定向。问题已添加编辑。我想要脚本的“document.writeln(“helloworld”);”部分,它必须是字符串。
<script src="script.js"></script>