zoukankan      html  css  js  c++  java
  • javascript:入门笔记

    1:html注释:

    <html>
    <body>
    <script type="text/javascript">
    <!--
    document.write("Hello World!");
    //两个正斜杠是 JavaScript 的注释符号,它会阻止 JavaScript 编译器对这一行的编译-->
    </script>
    </body>
    </html>

    2:支持三元运算符

    greeting=(visitor=="PRES")?"Dear President ":"Dear ";

    3:三种消息框

    警告框:alert("text")

    确认框:confirm("text")

    提示框:prompt("noon",12)

     4:类似python的for in

    var x
    var mycars = new Array()
    mycars[0] = "Saab"
    mycars[1] = "Volvo"
    mycars[2] = "BMW"
    
    for (x in mycars)
    {
    document.write(mycars[x] + "<br />")
    }

     5:异常处理

    <html>
    <body>
    <script type="text/javascript">
    while(true){
    var x=prompt("Enter a number between 0 and 10:","")
    try
    { 
    if(x>10) 
    throw "Err1"
    else if(x<0)
    throw "Err2"
    else
    break
    } 
    catch(er)
    {
    if(er=="Err1") 
    alert("Error! The value is too high")
    if(er == "Err2") 
    alert("Error! The value is too low") 
    }}
    </script>
    </body>
    </html

    6:显示时间

    <html>
    
    <head>
    <script type="text/javascript">
    function startTime()
    {
    var today=new Date()
    var h=today.getHours()
    var m=today.getMinutes()
    var s=today.getSeconds()
    // add a zero in front of numbers<10
    m=checkTime(m)
    s=checkTime(s)
    document.getElementById('txt').innerHTML=h+":"+m+":"+s
    t=setTimeout('startTime()',500)
    }
    
    function checkTime(i)
    {
    if (i<10) 
      {i="0" + i}
      return i
    }
    </script>
    </head>
    
    <body onload="startTime()">
    <div id="txt"></div>
    </body>
    
    </html>
  • 相关阅读:
    tcp的三次握手和四次挥手
    前端文档规范
    阻止事件冒泡
    研发纠纷解决方案
    ui-router 中views的配置
    JXL操作Excel部分详解(java)
    utf-8与utf-16的区别
    把字符串转换为Double 类型
    spring MVC
    Android项目目录结构
  • 原文地址:https://www.cnblogs.com/qwj-sysu/p/3831176.html
Copyright © 2011-2022 走看看