Write the first JavaScript code, using the web as an example
If you have written CSS syntax, it should be easy to write JavaScript, because the configuration is similar, but this is not the point. The following article will show you a simple JavaScript example in the form of a web page. There are three ways to write JavaScript. A simple step, the first step is to declare, that is, tell the browser that the code you wrote belongs to JavaScript syntax, so that the browser will execute it correctly, instead of displaying the code you wrote as a normal string , Of course, the second step is to write the code! The third step is testing. When writing this type of script, you usually write and test as you write it. If you have any problems, you should immediately modify it to avoid writing a long list of errors before you start debugging.
Now start to write the first JavaScript code. Please open Notepad or Notepade++ code editor , copy the following code to your Notepad or editor, and save the new file as test.html, and finally Open the test.html file test with a browser.
<body>
<script type="text/JavaScript">
<!--
document.write("Welcome")
//-->
</script>
</body>
</html>
The HTML part of this code is relatively simple (if you don’t understand HTML syntax, please refer to this article: Writing the first HTML page example ). The point is that the difference between <script type="text/JavaScript"> and </script> It is used to put your JavaScript grammar. When the browser sees the declaration of this Script tag, it knows to execute the JavaScript grammar. If you do not have such a declaration, JavaScript may not execute correctly!
Post a Comment
0 Comments