0

我正在尝试使用 Mathquill 进行一些简单的静态格式化。当我测试我的代码时,文本没有被格式化,也没有任何错误让我知道我是否做错了什么。

<html>
    <head>
        <style>
            <link rel="stylesheet" href="dist/mathquill/mathquill.css"/>
        </style>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
        <script src="dist/mathquill/mathquill.js"></script>
        <script>
            var MQ = MathQuill.getInterface(2);
            var problemSpan = document.getElementById('problem');
            MQ.StaticMath(problemSpan);
        </script>
    </head>
    <body>
        <p>Solve <span id="problem">ax^2 + bx + c = 0</span>.</p>
    </body>
</html>

所有路径都是正确的,因为没有 404 错误。

页面输出

4

1 回答 1

1

不需要样式标签,并且会干扰链接标签。需要等待 DOM 准备好。

<html>

<head>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mathquill/0.10.1/mathquill.css" />
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/mathquill/0.10.1/mathquill.js"></script>
  <script>
    window.addEventListener('DOMContentLoaded', () => {
      var MQ = MathQuill.getInterface(2);
      var problemSpan = document.getElementById('problem');
      MQ.StaticMath(problemSpan);
    });
  </script>
</head>

<body>
  <p>Solve <span id="problem">ax^2 + bx + c = 0</span>.</p>
</body>

</html>

于 2020-05-11T16:41:48.983 回答