从内容可编辑div获取已删除的字符 [英] Get deleted character from content editable div

查看:70
本文介绍了从内容可编辑div获取已删除的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用内容可编辑div ,因为我想显示用户在文本区域中选择的表情符号。



我想知道字符是已删除与退格 delete 按钮。



可以通过 / code>或 javascript



UPDATE b
$ b

这不是一个重复,因为所有的答案都是关于如何跟踪一个按下的键不是关于被选中的字符。

解决方案

我没有一个干净的解决方案。但是这一个显示你删除的字符,如果你击退退格键:

  var lastText = $('#editable')。文本(); 
$('#editable')。keyup(function(event){
if(event.which == 8 || event.which == 46){
var newText = $ this).text();
for(var i = 0; i if(lastText [i]!= newText [i]){
console.log($'+ lastText [i] +'在索引+ i处删除);
lastText = newText;
return;
}
}
}
});

演示


I am using a content editable div because i want to show emoticons selected by the user in the text area.

I want to know what character is deleted with backspace or delete button.

Is it possible to know the character with jquery or javascript?

UPDATE

This is not at all a duplicate, since all answer are about how to track a pressed key not about the delected character.

解决方案

I don't have a clean solution. But this one shows you the removed char if you hit the backspace key :

var lastText = $('#editable').text();
$('#editable').keyup(function(event){
  if (event.which==8 || event.which==46) {
     var newText =  $(this).text();
    for (var i=0; i<lastText.length-1; i++) {
      if (lastText[i]!=newText[i]) {
       console.log("char '" +  lastText[i] + "' was removed at index "+i);
        lastText = newText;
        return;
      }
    }
  }
});

Demonstration

这篇关于从内容可编辑div获取已删除的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆