2012-12-02 123 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>