• js基础语句


    1、

    <script>
    var color="blue";

    function a(){
    //var color="blue"
    if(color=="blue"){
     color="red";
    } else{color="blue"};

    }
    a();
    alert(color);
    </script>
    <script>
    function sayhi(){
      alert("dsvs")
    }

    </script>

    2、

    <title>switch判断</title>
    <script type="text/javascript">
    var cc=prompt("请输入喜欢的吃的水果!","")
    if(cc=="苹果"){
       alert(cc+"不错哦!")
    }
    if(cc=="香蕉"){
       alert(cc+"不错哦!")
    }
    if(cc=="橘子"){
       alert(cc+"不错哦!")
    }
    </script>

    <script>
      var x=2;
      switch (x){
             case 1:
             alert("ok!")
             break;
              case 2:
             alert("ok2!")
             break;
              case 3:
             alert("ok3!")
             break;
             default:
             alert("hello!")
     
     
      };
    </script>

    3、

    <style>
    div{ 100px; height:100px; float:left;  background:#CCC; border:1px #666666 solid; margin:0 10px 10px 0;}
    </style>
    <script>
    window.onload=function(){
        var but1=document.getElementsByTagName('button')[0];
        var box=document.getElementById('box');
            but1.onclick=function(){
                alert(box.innerHTML)
            };
            
            
        var but2=document.getElementsByTagName('button')[1];;
            but2.onclick=function(){
                box.innerHTML="<h1>ok</h1>"
            };
    };

    </script>
    </head>

    <body>
    <button>修改内容</button>
    <button>显示内容</button>
    <div id="box"><ul><li>ok</li></ul></div>

    4、

    <script>
    var ok;
    var cc=null;
    //alert(typeof ok)  //undefing
    //alert(typeof cc)  //object
    for(var i=0;i<10;i++){
      document.write(i+'<br/>')
    }
    </script>

  • 相关阅读:
    人月神话阅读笔记之二
    人月神话阅读笔记之三
    人月神话阅读笔记之一
    清楚浮动的10种方法
    WEB颜色值得设定
    文件上传 FileReader()
    Git学习笔记(三)
    Git学习使用笔记(二)
    Git使用学习笔记 (一)
    小知识点(JS)
  • 原文地址:https://www.cnblogs.com/su1637/p/8204514.html
Copyright © 2020-2023  润新知