简体   繁体   English

jQuery 更改 DOM 元素

[英]jQuery to change DOM element

I am testing a jQuery Library MathJax which gets Mathematics code in Latex format, and shows Mathematics expression in html.我正在测试一个 jQuery 库MathJax ,它以 Latex 格式获取数学代码,并以 html 显示数学表达式。

MathJax works - two ways - \ [ latex-code \ ] and \ ( latex-code \ ), in this code, jquery appends <p> tag, but I can not append, either \ ( \ ) or \ [ \ ] which are latex delimiters. MathJax 的作品 - 两种方式 - \ [ latex-code \ ] 和 \ ( latex-code \ ),在此代码中,jquery 附加<p>标签,但我不能 append,\ ( \ ) 或 \ [ \ ]是 latex 个分隔符。

I want the textbox has only the latex command, not the delimiters, which will be good for handling and testing latex, basically web-math testing.我希望文本框只有 latex 命令,没有分隔符,这将有助于处理和测试 latex,基本上是网络数学测试。

Can anyone, with jquery knowledge help this?有 jquery 知识的任何人都可以帮助这个吗? This does require, some DOM manipulation.这确实需要一些 DOM 操作。

Objective Textbox should not contain any delimiters, the delimiters should be anyway added by other methods.目标文本框不应包含任何分隔符,分隔符无论如何都应通过其他方法添加。

Bonus: 1 Can, button be removed - the jquery is to be updated on every input, and tries to render in every change of input奖励:1可以,按钮被删除 - jquery 将在每次输入时更新,并尝试在每次输入更改时呈现

Bonus: 2(can brake, not necessary) If possible, can there be two line, and after Enter inside textbox, the two expressions, get \\ delimiter between them, which will show Mathematics expression, in next line Bonus: 2(can brake, not necessary)如果可能的话,是否可以有两行,在文本框内输入后,这两个表达式,在它们之间得到\\分隔符,这将在下一行显示数学表达式

like: \sin(x) \ \tan(x) {two backslash between \sin(x), \tan(x) commands}像:\sin(x) \\tan(x) {\sin(x), \tan(x) 命令之间的两个反斜杠}

 $("#check").click(function (){ $("#qPreview").empty().append("<p>" + $("#input").val() + "</p>"); MathJax.typeset(["#qPreview"]); })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script> <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> <strong> Type Latex code Here:<br></strong> <input type="text" id=input class="form-control" value="\(\frac{a}{b}\)"> <div id="qPreview"></div> <button id="check">Click</button> </div>

I think the easiest way to accomplish this is to move the \( and \) outside of the input field and into #qPreview instead.我认为完成此操作的最简单方法是将\(\)移到输入字段之外并移至#qPreview中。 Additionally, you need to escape the \ in the prefix/postfix with another \ .此外,您需要使用另一个\ \ This keeps your input value as just \frac{a}{b} .这使您的input值保持为\frac{a}{b}

 let prefix = "\\("; let postfix = "\\)"; $("#input").on('input', function() { $("#qPreview").empty().append( "<p>" + prefix + $("#input").val() + postfix + "</p>" ); MathJax.typeset(["#qPreview"]); }).trigger('input');
 <script id="MathJax-script" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script> <strong> Type Latex code Here:<br></strong> <input type="text" id="input" class="form-control" value="\frac{a}{b}" autocomplete="off"> <div id="qPreview"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM