使用Script标记事例:

<HTML>
  <HEAD>
    <script language = "JavaScript">
      <!--对较早的浏览器隐藏脚本
       document.write("欢迎使用JavaScript");
     //脚本隐藏在此处结束
      -->
    </script>
  </head>
  <body>
    <P>祝学有所成!!!</P>
  </body>
</HTML>
 

new语句:
<html  >
<head>
    <title></title>
   
    <script language="javascript">
        function employee(name, code, designation) {//定义有参数的 对象
            this.name = name; //表示为对象添加新的属性name并把参数name的值赋给属性
            this.code = code;
            this.desigation = designation;
        }

        newemp = new employee("baiya", "124", "总工程师");
        document.write("姓名:" + newemp.name);
        document.write("编号:" + newemp.code);
        document.write("头衔:" + newemp.desigation);
    </script>
</head>
<body>

</body>
</html>
 

onResize事例:

<html>
<head>
 <script language="JavaScript">
  window.οnresize= notify;
  function notify()
  {
   alert("窗口大小调整完毕!");
  }
 
 </script>
</head>
<body>
 请调整窗口的大小。
</body>
</html>
 

with语句事例:
<html >
<head>
    <title></title>
    <script language = "javascript">
        var a, b, c;
        var r = 10;
        with (Math) {
            a = PI * r * r;//这里的PI相当于Math.PI
            b = r * cos(PI);
            c = r + sin(PI);
        }
        document.write(a + "<br>");
        document.write(b + "<br>");
        document.write(c + "<br>");
    </script>
</head>
<body>

</body>
</html>
 

多维数组:

<html  >
<head>
    <title></title>
    <script language="javascript">
        MyArray = new Array(5, 5); //多维数组
        MyArray[0, 0] = "yan";
        MyArray[0, 1] = 0;
        MyArray[1, 0] = "zhang";
        MyArray[1, 1] = "jiang";
        document.write("name:" + MyArray[0, 0]);
        document.write("    number:" + MyArray[0,1]);
    </script>
</head>
<body>

</body>
</html>
 

 

函数求各事例:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title></title>
    <script language="javascript">
        function hello() {
            document.write("你好,欢迎使用函数");
            return;
        }

        function sum_up(one, two) {
            var result = one + two;
            return result;
        }

        function sum_all() {
            var loop = 0,sum = 0;
            for (loop = arguments.length - 1; loop >= 0; loop--) {//用arguments对象可能获得所有的传入的参数
                sum = sum + arguments[loop];
            }
            return sum;

        }


        //执行
        hello();
        var total = sum_up(1, 2);
        document.write(total + " " + sum_up(1, 3));
        document.write(sum_all(1,2,3,4,5));
       
    </script>
</head>
<body>

</body>

数组赋值:

<html xmlns >
<head>
    <title></title>
    <script language="javascript">
        employee = new Array(3); //定义数组
        employee[0] = "I";
        employee[1] = " am";
        employee[2] = " Bai yan";
        document.writeln(employee[0]);
        document.write(employee[1]);
        document.write(employee[2]);
       
    </script>
</head>
<body>

</body>
</html>
 

this语句:

<html >
<head>
    <title></title>
    <script language="javascript">
        function welcome(name) {
            alert("欢迎进入JavaScript世界--" + name );
         }
    </script>
</head>
<body>

<form>
 <input type="text" name="text1" οnchange="welcome(this.form.text1.value)" />
</form>

</body>
</html>