admin管理员组

文章数量:1391964

There are many questions similar to this but none of them have been able to help me.

I am new to HTML and JS development. I have a simple HTML file that is trying to access a simple Javascript file.

HTML:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Sample</title>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
document.write("In HTML")

</script>

<script type="text/javascript" src=./asdf.js></script>
</head>
<body>
<div id="map3d" style="height:400px;width:600px;border:1px solid red"></div>
</body>

The Javascript file is named asdf and exists in the same location as the HTML. I have tried the full file path, just the name "asdf.js" and several other options I can't recall.

My .js file reads thusly:

<script>
document.write("In JS")
</script>

The "In JS" doesn't appear. What am I doing wrong?

There are many questions similar to this but none of them have been able to help me.

I am new to HTML and JS development. I have a simple HTML file that is trying to access a simple Javascript file.

HTML:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Sample</title>
<script type="text/javascript" src="https://www.google./jsapi"></script>
<script type="text/javascript">
document.write("In HTML")

</script>

<script type="text/javascript" src=./asdf.js></script>
</head>
<body>
<div id="map3d" style="height:400px;width:600px;border:1px solid red"></div>
</body>

The Javascript file is named asdf and exists in the same location as the HTML. I have tried the full file path, just the name "asdf.js" and several other options I can't recall.

My .js file reads thusly:

<script>
document.write("In JS")
</script>

The "In JS" doesn't appear. What am I doing wrong?

Share Improve this question asked Apr 18, 2013 at 20:30 Kyle WrightKyle Wright 5202 gold badges10 silver badges24 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

External scripts do not require <script> and </script>. Write external scripts as if you were writing in between the tags.

In your JS file remove the <script> and </script> tags. They are for using JavaScript embedded within HTML, not for external file.

本文标签: Access local Javascript file from a local HTML fileStack Overflow