我有以下问题。我需要将 hello 函数传递给 name,然后他们调用它。但我收到错误,hello 不是函数。
<html>
<head>
<title>D</title>
<script type="text/javascript">
hello = function(){
alert("hello! I'm called") ;
}
</script>
</head>
<body>
<script type="text/javascript">
name = function( hello ) {
hello() ;
}
name();
</script>
</body>
</html>
您正在定义一个名为的参数hello
within name()
,但你正在打电话name()
没有参数,因此hello
在上下文中未定义name()
。要么调用时传递参数name()
,或完全删除该参数:
name = function (hello) {
hello();
}
name(hello);
or
name = function() {
hello();
}
name();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)