我是日本人。 对不起,我不擅长英语!
我正在使用html5 contenteditable属性创建web editer(如wordpress)。
按下输入已适应contenteditable的元素,您可以创建div标签。 div标签的字符是我想确定是否是空的情况。
我写了这些代码。
<div class="c-contenteditable" contenteditable="true" id="js-editable"></div>
//In this case, console.log is all charactor in this element. I want to single line words, not all.
$('#js-editable').on('keyup', function(e) {
var $this = $(this);
var text = $this.text();
if ($this.text() == '') {
console.log('no words');
}else{
console.log(text);
}
});
//In this case, keyup t`enter code here`rigger is not run.
$('#js-editable div').on('keyup', function(e) {
var $this = $(this);
var text = $this.text();
if ($this.text() == '') {
console.log('no words');
}else{
console.log(text);
}
});
//In this case, keyup trigger is not run.
$('#js-editable').find('div').on('keyup', function(e) {
var $this = $(this);
var text = $this.text();
if ($this.text() == '') {
console.log('no words');
}else{
console.log(text);
}
});
当您按Enter in contenteditable属性时,如何在div标签中获取字符串?