码迷,mamicode.com
首页 > Web开发 > 详细

JS的返回值,函数的运行和setTimeout的用法

时间:2017-08-26 21:24:05      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:tle   comment   head   color   type   out   sum函数   alt   pre   

JS返回值的用法
<!DOCTYPE html>
<head>
  <title></title>
  <!--js中声明函数的方法-->
  <script type="text/javascript">
     
    function add(i, j) { //现在只是声明了一个函数在这里,只有调用到它的时候它才会被执行。 
      return i + j;
  
    }
    alert(add(5, 6)); //输出11 
  
    //js中并非所有路径都有返回值,如果没有返回值他就认为返回值是undefined 
    function sum(x, y) {
      if (x > y) {
        alert(x + y);
      }     
    }
    var z = sum(2, 6); //因为2并不大于6所以sum函数就没有返回值。如果没有返回值他就认为返回值是undefined。 
    alert(z); //所以它就输出了undefined 
          
  </script>
</head>
<body>
  
</body>
</html>
 
setTimeout用法
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h1> <font color=blue> ##### </font> </h1>
<p> 请等三秒!</p>

<script>
setTimeout("alert(‘对不起,要你等候多时‘)", 3000 )
</script>

</body> 
</html>
明天考虑学习用setTimeout来执行function
 
 

JS的返回值,函数的运行和setTimeout的用法

标签:tle   comment   head   color   type   out   sum函数   alt   pre   

原文地址:http://www.cnblogs.com/suntao12138/p/7436286.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!