gpt4 book ai didi

javascript - 限制 Javascript 打印输出中的字符

转载 作者:行者123 更新时间:2023-11-28 00:12:55 25 4
gpt4 key购买 nike

我试图限制带有js文件的标签上打印的字符数。我遇到问题的代码部分是通过按钮调用的,并从预览框中打印内容。除了我要打印的标题长度之外,一切正常。每当我添加代码来限制我得到的字符数时:类型错误:title.substring 不是函数标题 = 标题.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

最佳答案

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

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

关于javascript - 限制 Javascript 打印输出中的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30732810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com