sbc11

day5

学习了js的相关知识

点击查看代码
<html>
  <head>
    <title>$Title$</title>
    <script>
      window.alert("hadioho");
      document.write("isafhlsa");
      console.log("diasdo");
    </script>
  </head>
  <body>
 111
  </body>
</html>

js的基础语法

var关键字可以存放不同类型的值

点击查看代码
<html>
  <head>
    <title>Title</title>
    <script>
      var a;
      a = "张三";
      alert(a);
      //var 的作用域比较大,全局变量;
      //    可以重复定义;会覆盖以前的值;
      {
        var s =1;
      }
      alert(s);



      //let 是局部变量且不能重复定义
      {
        let x =1;
        alert(x);
      }

     //const 是常量;不能修改值;
      {
        const c = 2;
        alert(c);

      }
    </script>
  </head>
  <body>
 111
  </body>
</html>

数据类型

点击查看代码
<html>
  <head>
    <title>Title</title>
    <script>
      alert(typeof 3);
      alert(typeof "a");
      var a =10;
      alert(a==10);//ture
      alert(a=="10");//ture
      alert(a==="10");//false
      alert(parseInt("12"));//12
      alert(parseInt("12a34"));//12
      alert(parseInt("a14"));//NaN
    </script>
  </head>
  <body>
 111
  </body>
</html>

js函数

点击查看代码
      function add(a,b){
        return a+b;
      }
      var a=1 ,b=44;
      alert(add(a,b));

posted on 2025-01-21 15:56  沈八才11  阅读(14)  评论(0)    收藏  举报

导航