2012-12-02 58 views
0

我想要将位于hello.html上的<script></script>标记中的数据转换为index.html。我怎样才能做到这一点?从其他文件中获取数据

的index.html:

<head> 
<script> 
// some codes 
</script> 
</head> 

<body> 
<div> 
<!-- result will be come here --> 
</div> 
</body> 

</html> 

hello.html的:

<html> 

<head> 
</head> 

<body> 
<script> 
document.writeln("hello world"); 
</script> 
</body> 

</html> 

编辑:我希望 “document.writeln(” 世界你好 “);”部分,它必须是字符串。

+1

您更好的移动脚本传送至外部文件,那么你可以有'<脚本类型=“文本/ javascript“src =”myfile.js“>'在这两个.html文件中。否则,几乎不可能做你想要的东西。 –

+0

我同意暗影向导。 @doruk你的问题并不清楚,如果你想要使用JavaScript将数据从一个页面发送到另一个页面,请使用带查询字符串值的重定向。 – Warlock

+0

编辑已添加到问题中。我想要“document.writeln(”hello world“);”脚本的一部分,它必须是字符串。 – doruk

回答

1

将脚本单独保存为myScript.js然后您可以在两个html文件中都使用脚本包含标记! <script src="myScript.js"></script>

0

移动脚本到一个新的文件,如script.js,然后将其添加到这两个文件:

<script src="script.js"></script>