如何將函數計算出來的內容傳遞為變數。
<!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初學者,求大牛指教