我将查询附加到我的订单以生成条形码。代码必须单独附加到每个订单。当我们打印订单时,它们会批量打印,代码会出现一次以上。在每个实例上,它运行并生成条形码的多个副本。我试过阻止它,但似乎无法让它工作。有人可以发一个建议。我知道只有一次是理想的,但不可能从我正在使用的网站。
<script>
$('font[size="3"] b:not(.dont_run)').addClass('barcode_needed');
$('b.barcode_needed').each(function() {
$(this).append(' <div class="bcTarget">');
});
$('.bcTarget').each(function() {
$(this).barcode('G' + $(this).closest('b.barcode_needed').text(),'code128');
$(this).removeClass('bcTarget');
$(this).closest('b.barcode_needed').removeClass('barcode_needed').addClass('dont_run');
});
</script>
以下是整个代码:
<html>
<head>
<link href="/v/vspfiles/templates/ZuluLAX/css/Colors.css" rel="stylesheet" type="text/css">
<link href="/v/vspfiles/templates/ZuluLAX/css/Content_Area.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="">
<style type=text/css>
BODY {
FONT: 11px Verdana; COLOR: #000000; letter-spacing: -0.1em;
}
TABLE {
FONT: 11px Verdana; COLOR: #000000; letter-spacing: -0.1em;
}
TD {
FONT: 11px Verdana; COLOR: #000000; letter-spacing: -0.1em;
}
.pos_receipt td {
font-family: "Courier New", Courier, monospace;
}
span.WarehouseLocation
{
width:50px;
border-bottom-color: black;
border-bottom-style: dashed;
border-bottom-width: 1px;
}
</style>
<table cellpadding=0 cellspacing=0 width="100%" align="center" style="page-break-after:always;">
<tr>
<td align="center">
<table cellpadding=0 cellspacing=0 width=600>
<tr>
<td width="100%">
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="400">
<img src="v/vspfiles/templates/ZuluLAX/images/company/logo.jpg">
<div id="div_articleid_86">
</div>
</td>
<td width="200" align="right">
<table width=180 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=90 align=left colspan="2"> <b> <font style="font-size:18px;font-weight:bold;">PACKING SLIP </font> </b> </td>
</tr>
<tr>
<td width=90 align=left> <b>Date: </b> </td>
<td width=90> <b>Order#: </b> </td>
</tr>
<tr>
<td width=75 align=left> 06/09/2011 </td>
<td> <font size=3> <b>10196 </b> </font> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%"> <img src='/clear1x1.gif' width='1' height='1' border=0> </td>
</tr>
</table>
<script type="text/javascript" src="http://zululax.com/v/vspfiles/templates/ZuluLAX/js/jquery.js"> </script>
<script type="text/javascript" src="http://zululax.com/v/vspfiles/templates/ZuluLAX/js/jquery-barcode-2.0.2.min.js"> </script>
<script>
$('font[size="3"] b:not(.dont_run)').addClass('barcode_needed');
$('b.barcode_needed').each(function() {
$(this).append(' <div class="bcTarget">');
});
$('.bcTarget').each(function() {
$(this).barcode('G' + $(this).closest('b.barcode_needed').text(),'code128');
$(this).removeClass('bcTarget');
$(this).closest('b.barcode_needed').removeClass('barcode_needed').addClass('dont_run');
});
</script>
</div>
</td>
</tr>
</table>
<table cellpadding=0 cellspacing=0 width="100%" align="center" style="page-break-after:always;">
<tr>
<td align="center">
<table cellpadding=0 cellspacing=0 width=600>
<tr>
<td width="100%">
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="400">
<img src="v/vspfiles/templates/ZuluLAX/images/company/logo.jpg">
<div id="div_articleid_86">
</div>
</td>
<td width="200" align="right">
<table width=180 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=90 align=left colspan="2"> <b> <font style="font-size:18px;font-weight:bold;">PACKING SLIP </font> </b> </td>
</tr>
<tr>
<td width=90 align=left> <b>Date: </b> </td>
<td width=90> <b>Order#: </b> </td>
</tr>
<tr>
<td width=75 align=left> 06/09/2011 </td>
<td> <font size=3> <b>10197 </b> </font> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%"> <img src='/clear1x1.gif' width='1' height='1' border=0> </td>
</tr>
</table>
<script type="text/javascript" src="http://zululax.com/v/vspfiles/templates/ZuluLAX/js/jquery.js"> </script>
<script type="text/javascript" src="http://zululax.com/v/vspfiles/templates/ZuluLAX/js/jquery-barcode-2.0.2.min.js"> </script>
<script>
$('font[size="3"] b:not(.dont_run)').addClass('barcode_needed');
$('b.barcode_needed').each(function() {
$(this).append(' <div class="bcTarget">');
});
$('.bcTarget').each(function() {
$(this).barcode('G' + $(this).closest('b.barcode_needed').text(),'code128');
$(this).removeClass('bcTarget');
$(this).closest('b.barcode_needed').removeClass('barcode_needed').addClass('dont_run');
});
</script>
</div>
</td>
</tr>
</table>
<table cellpadding=0 cellspacing=0 width="100%" align="center" style="page-break-after:always;">
<tr>
<td align="center">
<table cellpadding=0 cellspacing=0 width=600>
<tr>
<td width="100%">
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="400">
<img src="v/vspfiles/templates/ZuluLAX/images/company/logo.jpg">
<div id="div_articleid_86">
</div>
</td>
<td width="200" align="right">
<table width=180 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=90 align=left colspan="2"> <b> <font style="font-size:18px;font-weight:bold;">PACKING SLIP </font> </b> </td>
</tr>
<tr>
<td width=90 align=left> <b>Date: </b> </td>
<td width=90> <b>Order#: </b> </td>
</tr>
<tr>
<td width=75 align=left> 06/09/2011 </td>
<td> <font size=3> <b>10198 </b> </font> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%"> <img src='/clear1x1.gif' width='1' height='1' border=0> </td>
</tr>
</table>
<script type="text/javascript" src="http://zululax.com/v/vspfiles/templates/ZuluLAX/js/jquery.js"> </script>
<script type="text/javascript" src="http://zululax.com/v/vspfiles/templates/ZuluLAX/js/jquery-barcode-2.0.2.min.js"> </script>
<script>
$('font[size="3"] b:not(.dont_run)').addClass('barcode_needed');
$('b.barcode_needed').each(function() {
$(this).append(' <div class="bcTarget">');
});
$('.bcTarget').each(function() {
$(this).barcode('G' + $(this).closest('b.barcode_needed').text(),'code128');
$(this).removeClass('bcTarget');
$(this).closest('b.barcode_needed').removeClass('barcode_needed').addClass('dont_run');
});
</script>
</div>
</td>
</tr>
</table>
</body>
</html>
答案 0 :(得分:3)
我认为问题是由乘法脚本代码引起的。如果是这样,那么:
最简单的解决方案是将您的代码放入document.redy
$(document).ready(function(){
//your script code
});
并将其放在外部文件中,该文件将在页面中加载:
<script type="javascript/text" src="Source of the file with your document.ready function" />
答案 1 :(得分:1)
最近有同样的问题。解决方案是检查元素或类:它是否存在?例如,我看到.bcTarget附加到.barcode_needed。 所以你可以这样检查:
$('b.barcode_needed').each(function() {
// if .bcTarget does not exist within current .barcode_needed, let's append
if ( !$(this).contents().is('.bcTarget') )
$(this).append('<div class="bcTarget"></div>');
});
希望,你已经抓住了这个主意。