我在ckeditor中使用数学公式,当我将文本输入到文本框中时,它会在下面放下文本并在ckeditor中显示正确的数学公式。
例如: 我输入了文字
\(x = {-b \pm \sqrt{b^2-4ac} \over 2a}\)
它将在ckeditor中放下文本并发布正确的数学格式..
这是我的来源:
<html>
<head>
<script type="text/x-mathjax-config">MathJax.Hub.Config({tex2jax: {inlineMath: [['\\(','\\)']]}});</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script src="https://cdn.ckeditor.com/4.7.3/standard/ckeditor.js"></script>
<script>
function displayResult() {
var first = CKEDITOR.instances.first.getData();
var maincontent = "";
maincontent = "<p>" + first + "</p>";
// CKEDITOR.instances.
document.getElementById("content").innerHTML = maincontent;
}
</script>
</head>
<body>
<input type="text" id="first" value="\(x = {-b \pm \sqrt{b^2-4ac} \over 2a}\)">
<button onclick="displayResult();">Click me!!!</button>
<span><div id="content"></div></span>
</body>
</html>
然而我发生错误:
未捕获的TypeError:无法读取未定义的属性'getData' 在displayResult(testMath.html:10)
在HTMLButtonElement.onclick(testMath.html:23)
如何修复此错误并显示正确的ckeditor格式?非常感谢!