我正在使用mathquill库将乳胶转换为方程式。如果乳胶有效,它将调用edit
处理程序。但是,如果粘贴的乳胶无效,则显示警报消息。如果错误,如何捕获粘贴的乳胶。
mathtext.js
var valid = false;
var mathFieldSpan = document.getElementById('math-field');
latexSpan = document.getElementById('latex');
hiddenSpanArea = document.getElementById('hiddenSpan');
mathField = MQ.MathField(mathFieldSpan, {
spaceBehavesLikeTab: true,
handlers: {
edit: function () {
latexSpan.textContent = mathField.latex();
valid = true;
}
}
});
window.mathField = mathField;
$(mathFieldSpan).keydown(function (e) {
if (e.keyCode == 86) { //keycode value for "v"
if (!valid) { // checks if the pasted value is not valid
alert("error")
}
valid = false;
}
});
mathtext.html
<span id="math-field"></span>
<span id="latex"></span>