黑马程序员技术交流社区
标题:
js函数调用问题
[打印本页]
作者:
唐志海
时间:
2014-2-17 11:34
标题:
js函数调用问题
为什么alert(show())除了弹出show run还会弹出 undefined的窗口呢。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>functionDemo.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<script type="text/javascript">
function show()
{
alert("show run");
}
alert(show());
//alert(show);//调用的是Object的toString方法
</script>
</body>
</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