LImit Java 脚本打印输出中的字符

LImit Characters in Java Script Print output

我正在尝试使用 js 文件限制打印在标签上的字符数。我遇到问题的代码部分由按钮调用,并从预览框中打印内容。除了我要打印的标题长度外,一切正常。每当我添加代码来限制我得到的字符数时: 类型错误:title.substring 不是一个函数 标题 = title.substring(0, 11);任何想法

// To allow for the TEMP SLU's to be printed from the main page in alpha order
$("#barcodesku").live('click', function(){
var title=[];
var sku=[];
var first = "";
var second = "";
var indexGlobal = 0;

    $('#acctRecords tbody tr').each(function()
 {
  sku.push($(this).find('#tableSKU').html());
  title.push ($(this).find('#tableTitle').html());
  
                
        });  //end of acctRecords tbody function
    
    //Print the bar codes
  title = title.substring(0,16);
  var x=0;
  for (x=0;x<sku.length;x++){
   
   
                        first += '$("#'+indexGlobal+'").barcode("'+sku[x]+'", "codabar",{barHeight:40, fontSize:30, output:"bmp"});';
   second += '<div class="wrapper"><img src="../images/temp.jpg" /><div id="'+indexGlobal+
   '"></div><div class="fullSKU">&nbsp &nbsp &nbsp '+sku[x]+'</div><br/><div class="title", {title.substring(0,16)}; >'+title[x]+' </div></div><br/><br/>';
   indexGlobal++;
   
      
    
     
   }
    var barcode =  window.open('','BarcodeWindow','width=200');
   var html = '<html><head><title>Barcode</title><style type="text/css">'+
      '.page-break{display:block; page-break-before:always; }'+
   'body{width: 2in;}'+
   '.wrapper{height: 1in;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

从你的代码中我看到 title 是一个标题数组。您需要执行以下操作:

for (var i = 0; i < title.length; i++) {
    title[i] = title[i].substring(0, 11); 
}