JavaScript的函数返回值无效...

来源:百度知道 编辑:UC知道 时间:2024/06/03 16:59:57
是教材上的代码,如下。
<html>
<head>
<title>Two Functions Program</title>
<script language="javascript">
<!--hide from incompatible browsers
function print_message(first_message)
{
document.writeln(first_message);
}
function return_message(second_message)
{
return "This message was returned from a function";
}
//stop hiding from incompatible browsers-->
</script>
</head>
<body>
<pre>
<script language="javascript">
<!--hide from incompatible browsers
var return_value=return_message();
print_message("This message was printed from a function");
//stop hiding from incompatible browsers-->
</script>
</pre>
</body>
</html>
已经核对过,跟书本一模一样了。可是在ie上面看的话,只能够显示结果为“This message was printed from a function”。按书本的结果,应该是还有一句

书上犯了一个低级的错误,你把
print_message("This message was printed from a function");
改一下:
print_message("This message was printed from a function"+return_value);

解释:return_message函数成功返回了值,但例子当中只是将这个值保存在一个变量当中,并没有显示出来,因此就看不到该有的效果了。

有问题欢迎找我讨论

问题2:有两个错误
第一个是第5行的</head>删掉;
第二个是confirmpagechange函数的问题,里面的内容要写在一行上,这样:
return confirm("Are you sure you want to dispalay the red page?");

var return_value=return_message();
你现在虽然调用了这个方法,得到了
return "This message was returned from a function";
返回结果,
但是你并没有输出它
document.write(return_value);

var return_value=return_message();没有输出的

<html>
<head>
<title>Two Functions Program</title>
<script language="javascript">
<!--hide from incompatible browsers
function print_message(first_message)
{
document.writeln(first_message);