在输入文本处显示平方根?

时间:2017-02-04 10:42:46

标签: javascript css html5 button sqrt

如何在带有上划线的calci按钮的输入文本框中显示平方根。例如,如果我们想要显示一个字符串80(√2345)68,其中平方根的上划线为2345(忽略大括号。)。请帮忙!!

3 个答案:

答案 0 :(得分:0)

您可以使用google charts infographic

例如:

<img src="https://chart.googleapis.com/chart?cht=tx&chl=\sqrt(1234)%2Ba^2">

会显示为enter image description here

答案 1 :(得分:0)

我认为您需要使用引擎来渲染与数学相关的文本/公式。一个受欢迎的是MathJax,请检查他们的Documentation

答案 2 :(得分:0)

MathJax扩展:forminput mathjax-ext-contrib sample

以下是上面示例的代码

<!DOCTYPE html>
<html>
<head>
<title>Add \Input to MathJax</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  extensions: ["http://cs.jsu.edu/mathjax-ext/github/forminput/forminput.js"],
  styles: {
    ".MathJax_Input": { "margin": "0 2px" },
    ".red_background": { "background-color": "#F88" }
  }
});
</script>

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

</head>
<body>

<p>
Here is an equation with form elements: 
\(\FormInput{a}x+\FormInput[][red_background]{b}\).
</p>

<p>
Here is another:
\[
\int_{\FormInput[][][2]{lowlim}}^{\FormInput{highlim}} x^3\,dx = 
\left.\frac{x^{\FormInput[2]{n}}}{\FormInput{m}}\right]_2^7
\]
</p>

</body>
</html>

修改

匹配表达问题

<!DOCTYPE html>
<html>
<head>
<title>Add \Input to MathJax</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  extensions: ["http://cs.jsu.edu/mathjax-ext/github/forminput/forminput.js"],
  styles: {
    ".MathJax_Input": { "margin": "0 2px" },
    ".red_background": { "background-color": "#F88" }
  }
});
</script>

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

</head>
<body>


<p>
  
 <b>square root in the input text box with overline</b> for 80(√2345)68
\[
\ 80\left(\sqrt{\FormInput[][][]{sqrt}}\right)68
\]

</p>

</body>
</html>