【问题标题】:How to correctly use <svg> tags with jquery in intellij?如何在intellij中正确使用带有jquery的<svg>标签?
【发布时间】:2020-09-28 22:39:14
【问题描述】:

所以这里我有 JQuery 和 jsbarcode 的 CDN -> jsbarcode info 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>

【问题讨论】:

  • 两件事:1)请edit您的问题添加您在查看网页时看到的内容。 2) 点击“Run code sn-p”按钮,查看出现的错误信息,看看修复是否有帮助。

标签: html jquery jsbarcode


【解决方案1】:

您需要在使用它们的代码之前为您的库添加脚本标签。他们可以进入&lt;head&gt; 标签。您的代码 sn-p 变为以下内容:

<!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>

(在我提供的代码 sn-p 中,我还清理了 HTML 中的一些错误,例如 &lt;/div&gt; 中不存在的 div 标签。)

【讨论】:

  • 由于某种原因它是空白的,似乎没有显示任何内容。
  • 我只是直接从我的答案中运行它并且它有效。加载确实需要大约一秒钟,但除此之外我不知道该告诉你什么。
  • 是的,对不起,我刚刚意识到我的一个 css 类正在干扰它。这完美地工作。谢谢
猜你喜欢
  • 1970-01-01
  • 2019-07-25
  • 2021-12-20
  • 1970-01-01
  • 2012-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-17
相关资源
最近更新 更多