说我在
HTML页面中有以下
JavaScript
<html> <script> var simpleText = "hello_world"; var finalSplitText = simpleText.split("_"); var splitText = finalSplitText[0]; </script> <body> <a href = test.html>I need the value of "splitText" variable here</a> </body> </html>
谢谢!
解决方法
<html> <script> var simpleText = "hello_world"; var finalSplitText = simpleText.split("_"); var splitText = finalSplitText[0]; window.onload = function() { //when the document is finished loading,replace everything //between the <a ...> </a> tags with the value of splitText document.getElementById("myLink").innerHTML=splitText; } </script> <body> <a id="myLink" href = test.html></a> </body> </html>