所以我写了1和6之间产生10张随机数的功能,我想我的HTML页面上显示的数字,这是数生成功能:document.write和return语句有什么区别?
function genereChiffre(){
var sResultat = "";
var iCompteur;
for(var i=0 ;i< 10 ;i++){
sResultat = Math.round(Math.random()* 6) + 1;
document.write("<li>" + sResultat + "</li>");
}}
这是显示功能数字:
(function(){
var aLesDiv = document.querySelectorAll("#global div");
aLesDiv[3].innerHTML = genereChiffre();
})();
我不明白的是,当我使用文件撰写方法和调用该函数为:genereChiffre()在控制台中,产生了10个号码,但是当我使用一回声明如此
return("<li>" + sResultat + "</li>");
它只产生1个数字。
的为这是内部STP产生li –
请看这个答案:http://stackoverflow.com/a/29290571/4275882。它解释了如何返回工作。 –
[可能是“返回”的副本意思是在JavaScript?](http://stackoverflow.com/questions/29290539/what-does-return-mean-in-javascript) – dfd