Jim*_*Jim 1 javascript tablesorter barcode barcode-printing jquery-barcode
我试图使用JS(表使用JQ Tablesorter)和条形码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">      '+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
Run Code Online (Sandbox Code Playgroud)
我很确定问题出在这些方面:
var x=0;
for (x=0;x<isbn.length;x++)
Run Code Online (Sandbox Code Playgroud)
例如,如果isbn是9780596515898,我在第一行得到9,在第二行得到7,在第三行得到8等等.如何让它在一行上打印出整个isbn?
不,那两行很好.但另一方面,这2个......
var isbn="";
...
isbn += $(this).find('#tableISBN').html();
Run Code Online (Sandbox Code Playgroud)
这是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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
161 次 |
| 最近记录: |