Vam's Notes

Just notes. But notes for everything.

导航

JavaScript

picture 

  • Comparison Operators
    Operator Description Example
    == is equal to 5==8 returns false
    === is equal to (checks for both value and type) x=5
    y="5"

    x==y returns true
    x===y returns false

  • Conditional Operator

    Syntax
    variablename=(condition)?value1:value2

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

  • Confirm Box
    <script type="text/javascript">
    function disp_confirm()
      
    {
      
    var r=confirm("Press a button")
      
    if (r==true)
        
    {
        document.write(
    "You pressed OK!")
        }

      
    else
        
    {
        document.write(
    "You pressed Cancel!")
        }

      }

    </script>

  • Prompt Box
    <script type="text/javascript">
    function disp_prompt()
      
    {
      
    var name=prompt("Please enter your name","Harry Potter")
      
    if (name!=null && name!="")
        
    {
        document.write(
    "Hello " + name + "! How are you today?")
        }

      }

    </script>

  • Break

    Example
    <script type="text/javascript">
    var i=0
    for (i=0;i<=10;i++)
    {
    if (i==3){break}
    document.write(
    "The number is " + i)
    document.write(
    "<br />")
    }

    </script>

    Result
    The number is 0
    The number is 
    1
    The number is 
    2

  • Continue

    Example
    <script type="text/javascript">
    var i=0
    for (i=0;i<=10;i++)
    {
    if (i==3){continue}
    document.write(
    "The number is " + i)
    document.write(
    "<br />")
    }

    </script>

    Result
    The number is 0
    The number is 
    1
    The number is 
    2
    The number is 
    4
    The number is 
    5
    The number is 
    6
    The number is 
    7
    The number is 
    8
    The number is 
    9
    The number is 
    10

posted on 2007-08-02 22:51  Vam  阅读(234)  评论(0编辑  收藏  举报