亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

How to pass what a function calculates as a variable
天蓬老師
天蓬老師 2017-06-26 10:55:07
0
2
953

How to pass the content calculated by the function into a variable.

<!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>

Like the code, use this calculation to output the image address I want, and then use the following code to display the image on the page

   <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" />

But how to pass the content calculated by the first paragraph of code to the second paragraph? ? ?
I am a JS beginner, please give me some advice

天蓬老師
天蓬老師

歡迎選擇我的課程,讓我們一起見證您的進步~~

reply all(2)
phpcn_u1582

? I think it’s okay to encapsulate the second code into a function that receives the image address as a parameter

小葫蘆

Judging from the meaning of the title, you return the calculated value inside the function, and when running this function, just use a variable to receive it.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template