Javascript 如何使用jquery打印多个条形码图像

Javascript 如何使用jquery打印多个条形码图像,javascript,jquery,barcode,barcode-printing,Javascript,Jquery,Barcode,Barcode Printing,我使用此代码生成了多个条形码: function getCode() { var multipleCodes = document.getElementById('codeArea').value; var eachLine = multipleCodes.split('\n'); console.log("eachLine = " + eachLine); for (var i = 0; i < eachLine.length; i++) {

我使用此代码生成了多个条形码:

function getCode() {
    var multipleCodes = document.getElementById('codeArea').value;
    var eachLine = multipleCodes.split('\n');
    console.log("eachLine = " + eachLine);
    for (var i = 0; i < eachLine.length; i++) {
        console.log("Inside loop: " + eachLine[i]);

        var div = document.createElement('iframe');
        div.innerHTML = "";

        div.setAttribute('id', 'iFrameID' + i);
        document.body.appendChild(div);
        document.getElementById('iFrameID' + i).src = 'barCodeGenerator/generateBarCode.php?q=' + eachLine[i];

    }
函数getCode(){
var multipleCodes=document.getElementById('codeArea')。值;
var eachLine=multipleCodes.split('\n');
console.log(“eachLine=“+eachLine”);
对于(var i=0;i
并尝试使用此方法打印它:

function printDiv(divName) {
    var strName = document.getElementById("codeArea").value;
    var imageId = document.getElementsByClassName('decoded');

    var imagObject = new Image();
    imagObject = imageId;
    var originalImage = '<img id="imageViewer" src="' + imageSrc + '" style="padding-top: 20px"   alt="' + imageSrc + '" />';
    popup = window.open('', 'popup', 'toolbar=no,menubar=no,width=700,height=650');
    popup.document.open();
    popup.document.write("<html><head></head><body onload='print()'>");
    popup.document.write(originalImage);
    popup.document.write("</body></html>");
    window.close('popup');
    popup.document.close();
    setTimeout(function () { popup.close(); }, 8000);
}
函数printDiv(divName){
var strName=document.getElementById(“codeArea”).value;
var imageId=document.getElementsByClassName('decoded');
var imagObject=新图像();
imagObject=imageId;
var originalImage='';
popup=window.open(“”,“popup”,“toolbar=no,menubar=no,width=700,height=650’);
popup.document.open();
popup.document.write(“”);
弹出。文档。写入(原始图像);
popup.document.write(“”);
window.close('popup');
popup.document.close();
setTimeout(函数(){popup.close();},8000);
}
通过合并所有条形码只打印单个图像。 如何将它们分别打印为多个图像。
任何帮助都会被赏识。

大部分代码与你的问题无关。考虑删除你的日志,显示弹出窗口的部分并隐藏它以获得更多的清除。

代码中的变量似乎
imageSrc
包含一个图像的源,因此您需要通过发送图像源数组并对其进行迭代来更改代码:

var originalImage = '';
// assuming imageSrc is an array of image sources
for (var i=; i < imageSrc.length; i++) {

    // note that I'm changing the id of the image a litle bit to ensure it will remain unique
    originalImage  += '<img id="imageViewer' + i + '" src="' + imageSrc[i] + '" style="padding-top: 20px"   alt="' + imageSrc[i] + '" />';

}
var originalImage='';
//假设imageSrc是一组图像源
for(var i=;i

然后剩下的代码必须工作。

您已经用普通JavaScript编写了这段代码,您可以将“JQuery”更改为“JavaScript”,而不丢失任何信息。我也做了同样的操作,但它不会打印条形码,它只会显示barCodeGenerator/generateBarCode.php?q='+strName(仅条形码字符串)@NehaDixit,如果您使用的是
src=“'+imageSrc+'”
以生成图像源,因此它是指向物理图像文件或其base64等效文件的url。不是吗?@NehaDixit很好!现在您需要将其更改为物理图像的url数组。只需将我的代码替换为代码的第6行即可。