开发者

Javascript syntax error... How can I find out more information?

开发者 https://www.devze.com 2022-12-14 05:45 出处:网络
Apologies if this is a stupid question as Im completly new to JAvascript and web programming! I\'m currently using Dreamweaver to do some test scripts and the internal JS editor is highlighting a syn

Apologies if this is a stupid question as Im completly new to JAvascript and web programming!

I'm currently using Dreamweaver to do some test scripts and the internal JS editor is highlighting a synt开发者_如何学运维ax error with my script. The only problem is that there is no indication as to what the error is or what I might need to do to fix it!

When I paste this code directly into the web page, the script seems to work without issue!

My script is as follows (saved in an external .js file):

1  // JavaScript Document
2  <script type="text/javascript">
3  
4  function coloralternatetablerows(id)
5  {
6      // If the tag exists within the document
7      if(document.getElementsByTagName)
8      {  
9          // rest of the script ommitted for clarity
10     }
11 }        

The synax error is highlighted as line 7.

Can anyone help me figure this out?!

More importantly... can anyone direct me to a good resource to help me with this sort of issue in the future?


Your Javascript code is in a seperate .js file so you don't need the <script> tag in there.

Get rid of the <script> tag completely.

In your HTML page you'll be loading in your external .js file using <script type="text/javascript" src="myscript.js"></script> but the .js file its self should have no HTML in it (like the <script> tag)


You need to pass an argument to the getElementsByTagName function:

if(document.getElementsByTagName('div'))


Do you mean:

if(document.getElementById(id) != null)

That'll check whether an element with your specified id exists.

0

精彩评论

暂无评论...
验证码 换一张
取 消