当前位置: 移动技术网 > IT编程>开发语言>JavaScript > JavaScript Math对象和调试程序的方法分析

JavaScript Math对象和调试程序的方法分析

2019年07月21日  | 移动技术网IT编程  | 我要评论
本文实例讲述了javascript math对象和调试程序的方法。分享给大家供大家参考,具体如下: math对象 <!doctype html>

本文实例讲述了javascript math对象和调试程序的方法。分享给大家供大家参考,具体如下:

math对象

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>math对象</title>
  <script type="text/javascript">
    var ipi=math.pi;
    // alert(ipi);
    var inum=math.random();
    // alert(inum);
    // var
    /*
    console.log是常用的调试程序的方法
    * */
    var arr=[];
    for(var i=0;i<20;i++){
      arr[i]=math.random();//math.random()只能返回从0到1之间的随机数
    }
    console.log(arr)//console.log()在谷歌浏览器中用console查看就能看见调试程序
  </script>
</head>
<body>
</body>
</html>

math对象能产生随机数等等,这就引出了除了alert()以外的另一个调试程序的方法,console.log(),其实还有document.title

调试程序的方法

一般不用document.title,alert()因为要弹出,所以会阻止函数的运行,console.log就不会有这个缺点。

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>title</title>
  <script type="text/javascript">
    window.onload=function () {
      var obody=document.getelementbyid('body1');
      var inum01=12;
      alert(inum01);
      obody.style.backgroundcolor='gold';
      var inum02=14;
      alert(inum02);
    }
  </script>
</head>
<body id="body1">
</body>
</html>

页面先弹出12,在改变颜色,再弹出14,但是由于渲染的比较慢,所以就县弹出12,再弹出14,在改变页面颜色

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>title</title>
  <script type="text/javascript">
    window.onload=function () {
      var obody=document.getelementbyid('body1');
      var inum01=12;
      // alert(inum01);
      console.log(inum01);
      obody.style.backgroundcolor='gold';
      var inum02=14;
      // alert(inum02);
      console.log(inum02);
    }
  </script>
</head>
<body id="body1">
</body>
</html>

这样的效果就是直接改变页面,然后console.log的值到console里面去找

更多关于javascript相关内容感兴趣的读者可查看本站专题:《javascript错误与调试技巧总结》、《javascript传值操作技巧总结》、《javascript编码操作技巧总结》、《javascript数据结构与算法技巧总结》及《javascript数学运算用法总结

希望本文所述对大家javascript程序设计有所帮助。

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网