Div+contenteditable 模拟 textarea 及存在的问题

2016-10-13 07:45:15

在网页端实现聊天功能时,大多会采用textarea来实现,但是当需要在textarea中显示表情/图片时,就不好实现了。这时候普遍的方法是给div添加contenteditable属性,来模拟textarea,而在div中显示图片及表情就可以轻松实现了。 The contenteditable global attribute is an enumerated attribute indicating if the element should be editable by the user. If so, the browser modifies its widget to allow editing. The attribute must take one of the following values: true or the empty string,