-2

Just downloaded Aptana 3 Studio for mac.

I was using Aptana 2 up until today. I am having trouble getting aptana to run my javascript code. It won't even display a simple alert message in an html file.

It is really frustrating me. New to programming and getting over these technical hurdles is a real pain sometimes.

I know my syntax isn't wrong. I have done much more complex code than this. Here is the alert message that won't even show:

<script type = "text//javascript">
     //<![CDATA[
     alert("Hello, World");
     //]]>
</script>

Any help would be appreciated.

4

1 回答 1

2

The MIME type for JavaScript only has one / character in it.

Browsers (and other tools that deal in HTML and JS) don't treat scripts with unrecognised MIME types as JavaScript.

HTML 5 makes the type attribute optional, so you can omit it entirely if you are dealing with JavaScript and avoid typos causing problems:

<script>
  alert("Hello, World");
</script>

(You can get rid of the CDATA too, it only matters if you are using characters with special meaning in XHTML in your script (you aren't, at least in this example) and are using XHTML).

于 2012-09-07T06:06:47.943 回答