加载了外部 javascript 不起作用,把js代码写到html里面却好使。这样修改一下就正常了。
Html内容:
1.
<html>
2.
<head>
3.
<script type=
"text/javascript"
src=
"my.js"
></script>
4.
<title>外部 javascript </title>
5.
</head>
6.
<body
Js内容:
01.
// JavaScript Document
02.
getText();
03.
function
getText()
04.
{
05.
var
textString=
""
;
06.
textString+=
'<div id="header-inner">'
;
07.
textString+=
'<div id="header-content">'
;
08.
textString+=
'<div id="header-name">'
;
09.
textString+=
'<a href="https://www.sothink.cn/" accesskey="1">SOTHINK</a>'
;
10.
textString+=
'</div>'
;
11.
textString+=
'<div id="header-description"></div>'
;
12.
textString+=
'</div>'
;
13.
textString+=
'</div>'
;
14.
document.getElementById(
"SOTHINK"
).innerHTML=textString;
15.
}
之前把JS放到外部不起作用,就是因为<body>里面没有加 onLoad="getText()" 这句话,浪费了我整整一天的时间。 - -||
本文结束。
Leave a comment