我试图制作一个网络表单来放入文本并将其打印在标签上。到目前为止,网络表单和打印一直在工作,但不知何故我更改了一些东西,它不再打印了。按钮停止工作,我花了几个小时尝试让它再次工作(我重新开始了几次(。有人可以帮我看看吗?
代码不会给出任何错误。
这是我的打印标签.JS
(function()
{
// called when the document completly loaded
function onload()
{
var printButton = document.getElementById('printButton');
// prints the label
printButton.onclick = function()
{
var txtMerk = document.getElementById('txtMerk');
var txtModel = document.getElementById('txtModel');
var txtOnderdeel = document.getElementById('txtOnderdeel');
var txtOnderdeelNr = document.getElementById('txtOnderdeelnr');
var txtPrijs = document.getElementById('txtPrijs');
var txtLoc = document.getElementById('txtLocatie');
var txtDonor = document.getElementById('txtDonor');
try
{
// open label
var BestandTePrinten = document.getElementById('txtMerk').value + '.label';
$.get(BestandTePrinten, function (labelXml) {
var label = dymo.label.framework.openLabelXml(labelXml);
// set label text
// select printer to print on
// for simplicity sake just use the first LabelWriter printer
var printers = dymo.label.framework.getPrinters();
if (printers.length == 0)
throw "No DYMO printers are installed. Install DYMO printers.";
var printerName = "";
for (var i = 0; i < printers.length; ++i) {
var printer = printers[i];
if (printer.printerType == "LabelWriterPrinter") {
printerName = printer.name;
break;
}
}
if (printerName == "")
throw "No LabelWriter printers found. Install LabelWriter printer";
// finally print the label
label.setObjectText('txtMerk', txtMerk.value);
label.setObjectText('txtModel', txtModel.value);
label.setObjectText('txtOnderdeel', txtOnderdeel.value);
label.setObjectText('txtOnderdeelnr', txtOnderdeelNr.value);
label.setObjectText('txtLoc', txtLoc.value);
label.setObjectText('txtPrijs', "€" + txtPrijs.value);
label.setObjectText('txtDonor', txtDonor.value);
label.print(printerName);
});
}
catch(e)
{
alert(e.message || e);
}
}
};
function initTests()
{
if(dymo.label.framework.init)
{
//dymo.label.framework.trace = true;
dymo.label.framework.init(onload);
} else {
onload();
}
}
// register onload event
if (window.addEventListener)
window.addEventListener("load", initTests, false);
else if (window.attachEvent)
window.attachEvent("onload", initTests);
else
window.onload = initTests;
} ());
这是我的索引.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Print A label</title>
<script src = "jquery-3.4.1.js" type="text/javascript" charset="UTF-8"></script>
<script src = "DYMO.Label.Framework.latest.js" type="text/javascript" charset="UTF-8"></script>
<script src = "PrintLabel.js" type="text/javascript" charset="UTF-8"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="container">
<div class="form-style-9">
<center><h2>Print Label</h2> </center>
<ul>
<li>
<select class="field-style field-split align-left" id="txtMerk">
<option value="Volkswagen">Volkswagen</option>
<option value="Audi">Audi</option>
<option value="Seat">Seat</option>
<option value="Skoda">Skoda</option>
<option value="Mercedes">Mercedes</option>
<option value="BMW">BMW</option>
<option value="Fiat">Fiat</option>
<option value="Ford">Ford</option>
<option value="Peugeot">Peugeot</option>
<option value="Citroen">Citroën</option>
<option value="Volvo">Volvo</option>
</select>
<input type="text" class="field-style field-split align-right" id="txtModel" placeholder="Model">
</li>
<li>
<input type="text" id="txtOnderdeel" placeholder="Onderdeel" class="field-style field-split align-left">
<input type="text" id="txtOnderdeelnr" placeholder="Onderdeelnummer" class="field-style field-split align-right">
</li>
<li>
<input type="text" id="txtLocatie" value="" class="field-style field-split align-left" placeholder="Locatie 2-1-A1">
<input type="text" id="txtPrijs" value="" class="field-style field-split align-right" placeholder="Prijs">
</li>
<li>
<textarea name="txtDonor" class="field-style" placeholder="Oorsprong onderdeel"></textarea>
</li>
<li>
<button id="printButton">Print</button>
</li>
</ul>
</div>
</div>
</body>
</html>
第一个可见检查 - 尝试更新:
(function()
{
// called when the document completly loaded
function onload()
{
自
$(function()
{
// called when the document completely loaded
// function onload()
{