黑马程序员技术交流社区

标题: js函数调用问题 [打印本页]

作者: 唐志海    时间: 2014-2-17 11:34
标题: js函数调用问题
为什么alert(show())除了弹出show run还会弹出 undefined的窗口呢。
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3.   <head>
  4.     <title>functionDemo.html</title>
  5.         
  6.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  7.     <meta http-equiv="description" content="this is my page">
  8.     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  9.    
  10.     <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  11.   </head>
  12.   
  13.   <body>
  14.     <script type="text/javascript">
  15.             function show()
  16.             {
  17.                     alert("show run");
  18.             }
  19.             alert(show());
  20.             //alert(show);//调用的是Object的toString方法
  21.     </script>
  22.   </body>
  23. </html>
复制代码

作者: webform    时间: 2014-2-17 13:10
alert() 里面的参数类型纯文本,JavaScript中数据的类型是弱类型,所以不会强制报错。但会有一些错误提示。最好不要这么写!
作者: baihe    时间: 2014-2-17 16:21
testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest
作者: 梵天的梦    时间: 2014-2-17 17:11
alert的参数不能为空,show()函数没有返回值,所以当alert(show())时就会出现 undefined,如果在show里面加上return "show run";不会出现undefined了。




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2