Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JS中长度的正确使用_Javascript_Barcode_Tablesorter_Barcode Printing_Jquery Barcode - Fatal编程技术网

Javascript JS中长度的正确使用

Javascript JS中长度的正确使用,javascript,barcode,tablesorter,barcode-printing,jquery-barcode,Javascript,Barcode,Tablesorter,Barcode Printing,Jquery Barcode,我试图使用JS(该表使用jqtablesorter)和条形码jquery从表中打印标签(条形码)。我的问题是我需要遍历所有的isbn,它每行显示一个数字。以下是我的代码: $("#barcode").live('click', function(){ var title=""; var isbn=""; var first = ""; var second = ""; var indexGlobal = 0; $('#acctRecords tbody tr').each(functi

我试图使用JS(该表使用jqtablesorter)和条形码jquery从表中打印标签(条形码)。我的问题是我需要遍历所有的isbn,它每行显示一个数字。以下是我的代码:

    $("#barcode").live('click', function(){
var title="";
var isbn="";
var first = "";
var second = "";
var indexGlobal = 0;

$('#acctRecords tbody tr').each(function()
{
    isbn += $(this).find('#tableISBN').html();
    title += $(this).find('#tableTitle').html();

    });  //end of acctRecords tbody function

//Print the bar codes

    var x=0;
    for (x=0;x<isbn.length;x++)
        {


        first += '$("#'+indexGlobal+'").barcode("'+isbn[x]+'", "codabar",{barHeight:40, fontSize:30, output:"bmp"});';
        second += '<div class="wrapper"><div id="'+indexGlobal+'"></div><div class="fullSKU">&nbsp &nbsp &nbsp '+isbn[x]+
        '</div><br/><div class="title">'+title[x]+'</div></div><br/><br/>';
        indexGlobal++;

        }
var barcode =  window.open('','BarcodeWindow','width=400');
        var html = '<html><head><title>Barcode</title><style type="text/css">'+
        '.page-break{display:block; page-break-before:always; }'+
        'body{width: 8.25in;-moz-column-count:2; -webkit-column-count:2;column-count:2;}'+
        '.wrapper{height: 2.5in;margin-left:10px;margin-top:5px;margin-right:5px;}'+
        '.fullSKU{float: left;}'+
        '.shortSKU{float: right;font-size:25px;font-weight:bold;}'+
        '.title{float: left;}'+
        '</style><script type="text/javascript"src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.js"></script><script type="text/javascript" src="../barcode/jquery-barcode.js"></script><script>$(document).ready(function() {'+first+'window.print();window.close();});</script></head><body>'+second+'</body></html>';
        barcode.document.open();
        barcode.document.write(html);
        barcode.document.close();

}); // end of click function
$(“#条形码”).live('click',function(){
var title=“”;
var isbn=“”;
var first=“”;
var second=“”;
var indexGlobal=0;
$('#acctRecords tbody tr')。每个(函数()
{
isbn+=$(this).find('#tableISBN').html();
title+=$(this.find('#tableTitle').html();
});//acctRecords tbody函数的结尾
//打印条形码
var x=0;

对于(x=0;xNope),这两条线很好。但另一方面,这两条线

var isbn="";
...
isbn += $(this).find('#tableISBN').html();
这使得
isbn
成为一个字符串。每次向其中添加isbn时,您都会使字符串变长。
“string”。length
将告诉您该字符串中的字符数,这就是为什么每次迭代都会得到一个字符

您需要一个数组,使用
[].push()
方法将项目附加到该数组。
[].length
将告诉您该数组中的项目数

var isbn = [];
...
isbn.push($(this).find('#tableISBN').html());
for (var x=0; x<isbn.length; x++) {
  isbn[x]; // one isbn
}
var-isbn=[];
...
isbn.push($(this).find('#tableISBN').html());

对于(Varx=0;xNope),这两条线是好的。但另一方面,这两条线

var isbn="";
...
isbn += $(this).find('#tableISBN').html();
这使得
isbn
成为一个字符串。每次向其中添加isbn时,您都会使字符串变长。
“string”。length
将告诉您该字符串中的字符数,这就是为什么每次迭代都会得到一个字符

您需要一个数组,使用
[].push()
方法将项目附加到该数组。
[].length
将告诉您该数组中的项目数

var isbn = [];
...
isbn.push($(this).find('#tableISBN').html());
for (var x=0; x<isbn.length; x++) {
  isbn[x]; // one isbn
}
var-isbn=[];
...
isbn.push($(this).find('#tableISBN').html());

for(var x=0;xIt)同样值得注意的是,那些通过“id”重复搜索的行为是高度可疑的。这不是胡说,但确实有点可疑。@Pointy我总是乐于接受让自己变得更好的建议。同样值得注意的是,那些通过“id”重复搜索的行为他们非常可疑。这不是胡说八道,但确实有点可疑。@Pointy我总是乐于接受让我变得更好的建议。