如何将函数计算出的内容传递为变量。
<!DOCTYPE html>
<html lang="zh">
<head>
<title>照片爬取</title>
<meta charset="UTF-8">
</head>
<body>
<script>
var a = 0;
function photo() {
while (a < 10) {
a = a + 1;
var url = "http://work.ynzs.cn/ZSGL/servletphoto?path=kszp/22240205/300y00" + a + ".jpg";
document.write(url + ",");
}
while (a < 100) {
a = a + 1;
var url = "http://work.ynzs.cn/ZSGL/servletphoto?path=kszp/22240205/300y0" + a + ".jpg";
document.write(url + ",");
}
}
</script>
<input name="button" type="button" onClick="photo()" value="NEXT" />
</body>
</html>
如代码,通过这样的计算来输出我要的图片地址,然后通过下面的代码在页面上展示图片
<script>
var img = “图片地址”;
var body = document.querySelector('body');
var imgArr = img.split(",");
var tem, j = 0;
document.querySelector('#showall').addEventListener('click', showa);
function showa() {
for (j; j < imgArr.length; j++) {
tem = document.createElement('img');
tem.src = imgArr[j];
body.appendChild(tem);
}
}
</script>
<input name="button" type="button" onClick="showa()" value="show" />
但是如何把第一段代码计算出的内容传递给第二段???
本人JS初学者,求大牛指教