Javascript Example


Example : the alert prompts

In order to facilitate an intuitive understanding of JavaScript, this section will provide a few simple examples for JavaScript portal learning purposes.

The following code is an example of a pop-up prompt:
<script type="text/javascript">
   alert("I was prompted text!");
</script>

Save the above code to alert.html (or alert.htm) with a text editor such as WordPad or another more advanced editor such as EditPlus. Double-click the alert.html run it (actually use IE and other browsers to open the file), will see the following pop-up prompt box:




Grammar explanation

  1. <script type="text/javascript"> represents the beginning of the JavaScript code, </script> represents the end. JavaScript code should be placed between the beginning and the end.
  2. Function alert() is the Javascript code
  3. The text of function alert() is enclosed by "" or ''



Copyright 2014-2017 by DeveloperTut.com. All Rights Reserved.
TwitterGoogle+Facebook