首页 > 解决方案 > 如何解决“我们这次不执行 document.execCommand(),因为它是递归调用的”execCommand delete

问题描述

我正在使用 html5 制作表单并使用 jquery 验证字段,如果在文本字段中输入一个数字,则会立即通过 document.execCommand('delete') 将其删除,但我收到此错误在控制台开发者工具中

<input type="text" id="fieldText" placeholder="First name">
$('#fieldText').on('input', function(e){
    let keyPressedNow = e.originalEvent.data;
    if (keyPressedNow >= 0 && keyPressedNow <= 9) {
        if (document.execCommand("delete")) {
            console.log(e.originalEvent.data+' -successfully deleted')
        }
    }

We don't execute document.execCommand() this time, because it is called recursively.

这个错误是什么意思,我该如何解决?

标签: javascriptjqueryhtmlcommandexec

解决方案


推荐阅读