可能重复:
Stop jquery from repeating, example attached有jQuery的只运行一次
我附上查询到我的订单生成条形码。代码必须分别附加到每个订单上。当我们打印我们的订单时,他们会分批打印,代码会多次出现。它在每个实例上运行并生成条码的多个副本。我试图阻止它,但似乎无法得到它的工作。有人可以发送一个建议。我知道只有一次是理想的,但不能从我正在使用的网站中获得。
<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>
你的问题的区别在哪里[停止jquery重复,示例附加](http://stackoverflow.com/questions/6307028/stop-jquery-from-repeating-example-attached)? – 2011-07-02 13:04:53