JS监听删除按键Backspace,判断标签全部删除

  • Post author:
  • Post category:其他


<input type="text" id="Keyword" />
 document.onkeydown = function (event) {
            var Keyword= $('#Keyword').val();
            if (event.key == "Backspace" && Keyword.charAt(Keyword.length - 1) == "]") {
                var name = Keyword.substring(Keyword.lastIndexOf("["));
                console.log(name)
                console.log(event, Keyword);
                $('#Keyword').val(Keyword.substring(0, Keyword.lastIndexOf(name)+1))
            }
           // console.log(event);

        }



版权声明:本文为weixin_38110122原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。