簡體   English   中英

循環邏輯根據輸入值循環圖像

[英]For loop logic to loop an image based by input value

在我解釋之前,這里是當前代碼:

function imageSource(source) {
    return "<img src='" + source + "' />";
}
function ImagetoPrint(title, source) {
    return "<html><head><script>function step1(){\n" +
            "setTimeout('step2()', 10);}\n" +
            "function step2(){window.print();window.close()}\n" +
            "</scri" + "pt></head><body onload='step1()'>\n" +
            "<h3>" + title + "</h3>" +
            imageSource(source) + "</body></html>";
}
function PrintImage(title, source) {
    Pagelink = "about:blank";
    var qty = $("#qrQty").val();
    var pwa = window.open(Pagelink, "_new");
    for (var i = 1; i <= qty; i++) {
        imageSource(source);
    }
    pwa.document.open();
    pwa.document.write(ImagetoPrint(title, source));
    pwa.document.close();
}

我想循環通過 ImagetoPrint function 調用的 imageSource function,以及通過 PrintImage function 調用的 ImagetoPrint function。

聽起來令人困惑,但我想做的是嘗試根據“qrQty”的輸入 ID 值循環圖像,例如,如果“qrQty”的值為 3,則圖像循環 3 次.

解決了它,通過用空引號聲明一個新的 var 然后將它添加到 for 循環中

function ImagetoPrint(title, source) {
    return "<html><head><script>function step1(){\n" +
            "setTimeout('step2()', 10);}\n" +
            "function step2(){window.print();window.close()}\n" +
            "</scri" + "pt></head><body onload='step1()'>\n" +
            "<h3>" + title + "</h3>" +
            source + "</body></html>";
}
function PrintImage(title, source) {
    Pagelink = "about:blank";
    var qty = $("#qrQty").val();
    var pwa = window.open(Pagelink, "_new");
    var img = "";
    for (var i = 1; i <= qty; i++) {
        var img = img+"<img src='" + source + "' />";
    }
    pwa.document.open();
    pwa.document.write(ImagetoPrint(title, img));
    pwa.document.close();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM