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

在上面的代码中,我试图在 textarea 中显示乳胶方程。每个方程的渲染如下。

$('#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)

那么,如何解决这个问题

4

1 回答 1

4

Looks like you need to use double \\ instead of a single \.

Change this:

function clickMe()
{       
  $('#taOne').mathquill('latex', 'x^2');
  $('#taTwo').mathquill('latex', '\int x');
  $('#taThree').mathquill('latex', '\left(x^2 + y^2 \right)');
}

to:

function clickMe()
{       
  $('#taOne').mathquill('latex', 'x^2');
  $('#taTwo').mathquill('latex', '\\int x');
  $('#taThree').mathquill('latex', '\\left(x^2 + y^2 \\right)');
}

\ is used in Strings to escape special characters, so if you want a backslash in your string, you have to escape it via another backslash.

于 2015-03-19T14:27:31.593 回答