zoukankan      html  css  js  c++  java
  • JavaScript基础-2

        javascript的基本语法,javascript具有所有语言都具有的所有程序结构:顺序/分支/循环这三种结构。

    if语句的例子:

       1: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
       2: <html>
       3:     <head>
       4:         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
       5:         <title>Untitled Document</title>
       6:         <script type="text/javascript">
       1:  
       2:             function testIF(){
       3:                 var tempTextBox = document.getElementById("number").value;
       4:                 
       5:                 if(tempTextBox>10)
       6:                 {
       7:                     alert("您输入的数字大于10");
       8:                 }
       9:                 else
      10:                 {
      11:                     alert("您输入的数字小于10");
      12:                 }
      13:             }
      14:         
    </script>
       7:     </head>
       8:     <body>
       9:         <form id="testform">
      10:             <input type="text" id="number" value="">
      11:             <input type="button" value="判断" onclick="testIF()">
      12:         </form>
      13:     </body>
      14: </html>

    for语句的例子:

       1: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
       2: <html>
       3:     <head>
       4:         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
       5:         <title>Untitled Document</title>
       6:         <script type="text/javascript">
       1:  
       2:             function testFor()
       3:             {
       4:                 var tempValue=document.getElementById("testFor").value;
       5:                 for(i=0;i<tempValue;i++)
       6:                 {
       7:                     alert(i);
       8:                 }
       9:             }
      10:         
    </script>
       7:     </head>
       8:     <body>
       9:         <input type="text" id="testFor">
      10:         <input type="button" id="demoid" value="点击" onclick="testFor()">
      11:     </body>
      12: </html>

    在javascript中我们也支持面对对象,只不过是模拟出来的。

       1: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
       2: <html>
       3:     <head>
       4:         <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
       5:         <title>Untitled Document</title>
       6:         <script type="text/javascript">
       1:  
       2:  
       3:                 var Person=new Object();
       4:                 function sum(a,b)
       5:                 {
       6:                     return a+b;
       7:                 }
       8:                 
       9:                 Person.sum=sum;
      10:                 //sum是一个属性还是一个方法要看后面跟的是一个什么
      11:                 alert(Person.sum(3,5));
      12:                 //可以使用匿名函数的方式来实现方法的声明
      13:                 Person.age=function(){return 8+8;};
      14:                 alert(Person.age());
      15:                 //带参数的匿名函数
      16:                 Person.test=function(a,b){return a+b};
      17:                 alert(Person.test(4,6));
      18:                 
      19:                 //以下方式是为了模拟属性的实现
      20:                 Person.Age=20;
      21:                 Person.setAge=function(a){Person.Age=a};
      22:                 Person.setAge(555);
      23:                 alert(Person.Age);
      24:         
    </script>
       7:     </head>
       8:     <body >
       9:     </body>
      10: </html>

     

  • 相关阅读:
    Enterprise Library 企业库 V4.1
    跨域实现IFRAME自适应高度
    微软企业库4.1学习笔记(二)各功能之间的依赖关系以及对象创建
    微软企业库4.1学习笔记(三)企业库迁移和并行使用,以及企业库的扩展
    微软企业库4.1学习笔记(五)对象创建和依赖注入方法
    判断 iframe 是否加载完成的完美方法
    对JavaScript调用堆栈和setTimeout用法的深入研究
    工作流技术杂谈
    企业流程管理平台V2.0介绍(.NET平台下的工作流)
    c#操作oracle lob字段[转自 芽芽的回收站]
  • 原文地址:https://www.cnblogs.com/chu888chu888/p/1334250.html
Copyright © 2011-2022 走看看