zoukankan      html  css  js  c++  java
  • javascript 学习随笔1

    html部分

    <body onload="message()"><!--主题部分加载就调用-->
    document.getElementById("demo").innerHTML=myFunction(4,3);<!-- 将函数返回值显示在指定的地方 -->

     javascript部分

    var r=Math.random()
    //产生0-1的随机数
    function disp_alert()
    {
    alert("我是警告框!!")
    }
    //弹出警告框

    function disp_alert()
    {
    alert("再次向您问好!在这里,我们向您演示" + ' ' + "如何向警告框添加折行。")
    }
    //带折行的警告框

    function show_confirm()
    {
    var r=confirm("Press a button!");
    if (r==true)
      {
      alert("You pressed OK!");
      }
    else
      {
      alert("You pressed Cancel!");
      }
    }//确认框

    function disp_prompt()
      {
      var name=prompt("请输入您的名字","Bill Gates")
      var age=prompt("请输入您的年龄","18")
      if (name!=null && name!="")
        {
        document.write("你好!" + name + " 今年" + age + "岁")
        }
      }//弹出输入框 ,有提示prompt("文本","默认值")

    调用带参数的函数

    <html>
    <head>
    
    <script type="text/javascript">
    function myfunction(txt)
    {
    alert(txt)
    }
    </script>
    
    </head>
    <body>
    
    <form>
    <input type="button" onclick="myfunction('您好!')" value="调用函数">
    </form>
    
    <p>通过点击这个按钮,可以调用一个带参数的函数。该函数会输出这个参数。</p>
    
    </body>
    </html>
    

    用返回值传参

    <html>
    <head>
    
    <script type="text/javascript">
    function myFunction()
    {
    return ("您好,祝您愉快!")
    }
    function product(a,b)
    {
    return a*b
    } </script> </head> <body> <script type="text/javascript"> document.write(myFunction());
    document.write(product(6,5)); </script> <p>用返回值传参</p> </body> </html>

    for循环

    <script type="text/javascript">
    var a=0;
    for (i = 0; i <= 5; i++)
    {
    a=a+i;
    }
    document.write(a)
    </script>
    

     while循环

    i = 0
    while (i <= 5)
    {
    document.write("数字是 " + i)
    document.write("<br />")
    i++
    }
    

     do-while循环

    i = 0
    do
    {
    document.write("数字是 " + i)
    document.write("<br />")
    i++
    }
    while (i <= 5)
    

    break跳出循环

    <script type="text/javascript">
    var i=0
    for (i=0;i<=10;i++)
    {
    if (i==3){break}
    document.write("数字是 " + i)
    document.write("<br />")
    }
    </script>
    

    continue中断当前循环执行下一步

    <script type="text/javascript">
    var i=0
    for (i=0;i<=10;i++)
    {
    if (i==3){continue}
    document.write("数字是 " + i)
    document.write("<br />")
    }
    </script>
    

    使用for-in遍历数组

    <script type="text/javascript">
    var x
    var mycars = new Array()
    mycars[0] = "宝马"
    mycars[1] = "奔驰"
    mycars[2] = "宾利"
    
    for (x in mycars)
    {
    document.write(mycars[x] + "<br />")
    }
    </script>
    

    使用for循环遍历数组

    for (var i=0;i<cars.length;i++)
    {
    document.write(cars[i] + "<br>");
    }
    

    解析字符串返回浮点数

    <script type="text/javascript">
    
    document.write(parseFloat("10")) //10
    document.write(parseFloat("10.00")) //10 
    document.write(parseFloat("10.33")) //10.33
    document.write(parseFloat("34 45 66")) //34 45 66
    document.write(parseFloat(" 60 ")) //60
    document.write(parseFloat("40 years")) //40
    document.write(parseFloat("He was 40")) //NAN
    document.write(parseFloat("3.14"))//3.14
    document.write(parseFloat("314e-2"))//3.14
    document.write(parseFloat("0.0314E+2"))//3.14
    document.write(parseFloat("3.14more non-digit characters"))//3.14
    </script>

    parseFloat 将它的字符串参数解析成为浮点数并返回。如果在解析过程中遇到了正负号(+ 或 -)、数字 (0-9)、小数点,或者科学记数法中的指数(e 或 E)以外的字符,则它会忽略该字符以及之后的所有字符,返回当前已经解析到的浮点数。同时参数字符串首位的空白符会被忽略。

    如果参数字符串的第一个字符不能被解析成为数字,则 parseFloat 返回 NaN。

    onmouseover动画

    <script type="text/javascript">
    function mouseOver()
    {
    document.b1.src ="/i/eg_mouse.jpg"
    }
    function mouseOut()
    {
    document.b1.src ="/i/eg_mouse2.jpg"
    }
    </script>
    </head>
    
    <body>
    <a href="/index.html" target="_blank">
    <img border="1" alt="Visit W3School!" src="/i/eg_mouse2.jpg" name="b1"  onmouseover="mouseOver()" onmouseout="mouseOut()" /></a>
    </body>
    
  • 相关阅读:
    Dapper使用
    EF5.X Code First表关联与延迟加载
    EF Code First 学习笔记:关系
    Entity Framework
    MVC3+EF4.1学习系列(五)----- EF查找导航属性的几种方式
    QML与C++混合编程
    如何将信号从javascript发射到qml
    qt quick中qml编程语言
    PyQt 5信号与槽的几种高级玩法
    静态编译OpenSSL并整合到Qt
  • 原文地址:https://www.cnblogs.com/tianhao/p/4277392.html
Copyright © 2011-2022 走看看