admin管理员组文章数量:1402156
It's a very simple one. The source of the webpage is
<script type="text/javascript" src="/jscript.js"></script>
<html><body>
<h1>It works</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body></html>
I put the js at the very beginning.
in jscript.js, it's:
<script type="text/javascript">
document.write("test text from bill!");
</script>
But it doesn't show the text. If I embed the js into html, it works.
And it's strange that when I directly access jscript.js from a webbrowser, the content is like:
<script type="text/javascript" src="/jscript.js">
</script><script type="text/javascript">
document.write("test text from bill!");
</script>
Can anybody help?
It's a very simple one. The source of the webpage is
<script type="text/javascript" src="/jscript.js"></script>
<html><body>
<h1>It works</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body></html>
I put the js at the very beginning.
in jscript.js, it's:
<script type="text/javascript">
document.write("test text from bill!");
</script>
But it doesn't show the text. If I embed the js into html, it works.
And it's strange that when I directly access jscript.js from a webbrowser, the content is like:
<script type="text/javascript" src="/jscript.js">
</script><script type="text/javascript">
document.write("test text from bill!");
</script>
Can anybody help?
Share Improve this question asked Feb 15, 2013 at 2:28 billtianbilltian 6,8514 gold badges21 silver badges28 bronze badges 3- a Script tag with a src attribute is not an include. As such, there's no document for the 'document.write' to write too. Even if there was, it'd write it before the opening HTML tag, which would also be pointless. Also your .js file has HTML tags in it, also wrong. – DA. Commented Feb 15, 2013 at 2:30
- By using John's answer, it works now. the document.write can also writ the text to the browser correctly. Thanks anyway – billtian Commented Feb 15, 2013 at 2:52
-
@billtian: Just because it works doesn't mean it's correct. It's not valid to have the
script
where you have it. The browser is performing corrections, but it's not guaranteed. – the system Commented Feb 15, 2013 at 3:05
2 Answers
Reset to default 6You don't need the <script type="text/javascript">
or </script>
in your javascript file. In fact, that's what is breaking everything. Remove them and it should work properly.
You shouldn't include tags in the JavaScript file.
Even if you remove them, your text will be written too early in the page, so I'm not certain that it will show up properly. Currently you're writing the text before the <html>
.
I'm not certain your <script>
location is even valid. Also, you've excluded the <head>
of the document, which would be required.
Proper structure for your page to write to the body
would be:
<html>
<head>
</head>
<body>
<script type="text/javascript" src="/jscript.js"></script>
<!-- your script will write the content right here -->
<h1>It works</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body>
</html>
本文标签: htmlJavascript src property doesn39t workStack Overflow
版权声明:本文标题:html - Javascript src property doesn't work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744345535a2601734.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论