原文地址:https://www.cnblogs.com/panjinzhao/p/15122783.html
<script> //JsBarcode("#barcode2", "6901236341384", { // text: "6901236341384",//覆蓋顯示的文本 // format:"EAN13",//選擇要使用的條形碼類型 // displayValue: true,//是否在條形碼下方顯示文字 // width: 0.84,//設置條之間的寬度 // height: 15,//高度 // margin: 0,//設置條形碼周圍的空白邊距 // textAlign:"right",//設置文本的水平對齊方式 //}); function generateBarcode() { // alert(pluc.mm2px(23) //將10mm轉化爲單位爲px的長度值,結果取整數 //) //alert( // pluc.mm2px(5.5) //將10mm轉化爲單位爲px的長度值,結果取整數 //) $("#bcTarget").empty().barcode( '6901236341384', "code93",{ output:'css', //渲染方式 css/bmp/svg/canvas //bgColor: '#ff0000', //條碼背景顏色 //color: '#00ff00', //條碼顏色 barWidth: 1, //單條條碼寬度 barHeight: 19, //單體條碼高度 // moduleSize: 5, //條碼大小 // posX: 10, //條碼座標X // posY: 5, //條碼座標Y addQuietZone: true, //是否添加空白區(內邊距) showHRI:true } ); } function code93(){ var value ="6901236341384"; var btype = "ean13"; var renderer = "css"; var settings = { output:renderer, bgColor: "#FFFFFF", color: "#000000", barWidth: 1, barHeight: 19, //moduleSize: $("#moduleSize").val(), //posX: $("#posX").val(), //posY: $("#posY").val(), addQuietZone: true }; $("#bcTarget").html("").show().barcode(value, btype, settings); } ///========================================js實現單位互換px/cm/mm篇========================================= ;(function(root, factory){ if(typeof define === 'function' && define.amd){ define(['pluc'], factory); }else if(typeof exports === 'object'){ module.exports = factory(require('pluc')); }else{ root.pluc = factory('pluc'); } })(this, function(pluc){ 'use strict'; var ratio = 0; var div = document.createElement('div'); div.style.width = '1cm'; div.id = 'puc'; document.body.appendChild(div); var w = getComputedStyle(div, null).width; ratio = w.substr(0, w.length - 2); div.parentNode.removeChild(div); return { px2cm :function(px) { return Math.round(px * 10 / ratio) / 10; }, px2mm : function(px) { var r = ratio / 10; return Math.round(px / r); }, cm2px : function(cm) { return Math.round(cm * ratio); }, mm2px : function(mm) { var r = ratio / 10; return Math.round(mm * r); } } }) ///=======================js實現單位互換px/cm/mm篇========================================================== </script>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="../js/jquery-barcodeV2_2.js"></script>
<div id="bcTarget" style="padding: 0px;margin-left: -6px; margin-top: 85px; width: 75px;" ></div>