return返回值跟document.write输出区别是什么?不能都直接打印出来么?
看透不说透
看透不说透 2016-12-20 13:30:22
0
3
1245

return跟被注释掉的输出函数

function  app2(x,y)
  { var sum,x,y;
    sum = x * y;
    return sum;
//document.write(sum = x * y + "</br>");
}
看透不说透
看透不说透

reply all(3)
数据分析师

What is the difference between return value and document.write output? Can't they all be printed directly? -PHP Chinese website Q&A-What is the difference between return value and document.write output? Can't they all be printed directly? -PHP Chinese website Q&A

Please watch and learn.

阿神

 return返回的这个值只是把结果返回,并未打印出来,返回的结果可以存在其他参数里面,方便以后的使用,而return如果要打印,还是得调用document.write,如document.write(app(2,3))打印2*3的值 

迷茫

你可以这样用,var result=app2(2,3),将返回的结果存在result里面,再输出打印document.write(result),这个函数app2()返回的是一个值,而不是打印输出,如果要打印就得再次调用document.write,而document.write(sum = x * y + "</br>")的情况下,调用函数就会打印输出,不存在返回值,就不能用result=app2(2,3)接收返回的值了

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!