<!DOCTYPE html>
<html>
<head>
<title>Mathquill</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="stylesheet" type="text/css" href="mathquill-0.9.4/mathquill.css">
<script src="jquery-1.9.1.min.js"></script>
<script src="mathquill-0.9.4/mathquill.min.js"></script>
<script>
function clickMe()
{
$('#taOne').mathquill('latex', 'x^2');
$('#taTwo').mathquill('latex', '\int x');
$('#taThree').mathquill('latex', '\left(x^2 + y^2 \right)');
}
</script>
</head>
<body style="height: auto">
<div id="MathOutput" style="display: none">$$ {} $$</div>
<div id="MathList" style="font-size:30px;background-color:LightSeaGreen;height: auto;line-height: 1.4;font-family: "Museo Sans",sans-serif; margin-bottom: 3px;" />
<div id="Ans1" class="mathquill-embedded-latex" style="background-color:yellow;text-align:left;font-size:30px;height: auto"></div>
<input type="button" value="ClickMe" onclick="clickMe();"/>
<textarea id="taOne" class="mathquill-editable" name="taOne" style="width:80%;vertical-align:top"></textarea>
<textarea id="taTwo" class="mathquill-editable" name="taTwo" style="width:80%;vertical-align:top"></textarea>
<textarea id="taThree" class="mathquill-editable" name="taThree" style="width:80%;vertical-align:top"></textarea>
</body>
</html>在上面的代码中,我试图在文本区域中显示latex方程。它为每个方程呈现如下所示。
$('#taOne').mathquill('latex', 'x^2');
:-x2
$('#taTwo').mathquill('latex', '\int x');
:-intx
$('#taThree').mathquill('latex', '\left(x^2 + y^2 \right)');
:-left(x^2+y^2ight)那么,如何解决这个问题?
发布于 2015-03-19 14:27:31
看起来您需要使用双\\而不是单个\。
改变这一点:
function clickMe()
{
$('#taOne').mathquill('latex', 'x^2');
$('#taTwo').mathquill('latex', '\int x');
$('#taThree').mathquill('latex', '\left(x^2 + y^2 \right)');
}至:
function clickMe()
{
$('#taOne').mathquill('latex', 'x^2');
$('#taTwo').mathquill('latex', '\\int x');
$('#taThree').mathquill('latex', '\\left(x^2 + y^2 \\right)');
}\在string中用于转义特殊字符,所以如果要在字符串中使用反斜杠,就必须通过另一个反斜杠来转义它。
https://stackoverflow.com/questions/28878609
复制相似问题