html - 如何正确使用
问题描述
所以在这里我有 JQuery 和 jsbarcode 的 CDN -> jsbarcode 信息https://lindell.me/JsBarcode/ 输出应该显示 const "number" var 的条形码。
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" >
</head>
<body >
</div>
<script>
const number = '12345678';
$(document).ready(function(){
JsBarcode("#barcode", number, {
text: number.match(/.{1,4}/g).join(" "),
width: 2,
height: 50,
fontSize: 15,
});
});
</script>
<svg id="barcode"></svg>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/jsbarcode/3.6.0/JsBarcode.all.min.js"></script>
</body>
</html>
解决方案
您需要在使用它们的代码之前为您的库添加脚本标签。他们可以进入<head>
标签内。您的代码片段如下:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/jsbarcode/3.6.0/JsBarcode.all.min.js"></script>
</head>
<body>
<script>
const number = '12345678';
$(document).ready(function(){
JsBarcode("#barcode", number, {
text: number.match(/.{1,4}/g).join(" "),
width: 2,
height: 50,
fontSize: 15,
});
});
</script>
<svg id="barcode"></svg>
</body>
</html>
(在我提供的代码片段中,我还清理了 HTML 中的一些错误,例如</div>
for a nonexistentdiv
标签。)
推荐阅读
- c - int_fast8_t 和 int_fast16_t 之间的区别
- c++ - (非升压)ASIO `Operation aborted` 错误
- javascript - 使用 DAG 对象将一维数组转换为二维数组
- sql - Oracle SQL - 带有 Where 子句的插入语句
- .net - 使用 NLog 仅将错误记录到 StdErr 输出流
- android - 如何将样式应用于自定义首选项 TimePicker?
- javascript - 为什么我不能设置底部标签栏的高度?
- class - 哪些类不是源自 Node,它们是如何合并到代码生命周期中的?
- javascript - 是否可以将 document.createElement 和 appendChild 的操作减少到 JS 中的一个命令中?
- apache-spark - 禁用或强制 Spark 哈希分区