mathquill Latex-如何通过代码移动光标(选择)?

Roy*_*Roy 3 html javascript latex mathquill

我正在使用 mathquill lib ( mathquill git ),我正在尝试使用 html 按钮制作键盘和退格键,但我不知道如何移动光标抛出公式。

谢谢,

小智 5

您可以在 mathquill 内的文本区域上触发自定义 keydown 事件,以在公式中移动光标。

var customKeyDownEvent = $.Event('keydown');

customKeyDownEvent.bubbles = true;
customKeyDownEvent.cancelable =true;
customKeyDownEvent.charCode = 37;  // 37 for left arrow key
customKeyDownEvent.keyCode = 37;   
customKeyDownEvent.which = 37;

$('.mathquill-editable textarea').trigger(customKeyDownEvent);
Run Code Online (Sandbox Code Playgroud)

使用 charCode / keyCode / 分别是:

  1. 37 为左箭头键
  2. 39 为右箭头键

谢谢。