首页 > 解决方案 > 如何正确使用 tags with jquery in intellij?

问题描述

所以在这里我有 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>

标签: htmljqueryjsbarcode

解决方案


您需要在使用它们的代码之前为您的库添加脚本标签。他们可以进入<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标签。)


推荐阅读