Javascript 如何在属性中获取contenteditable的字符
我是日本人。 对不起,我的英语不好 我正在使用html5 contenteditable属性创建类似web编辑器的wordpress 在已调整contenteditable的元素中按enter键,可以创建div标记。 div标记的字符是我想确定它是否为空 这是我写的代码Javascript 如何在属性中获取contenteditable的字符,javascript,jquery,css,html,Javascript,Jquery,Css,Html,我是日本人。 对不起,我的英语不好 我正在使用html5 contenteditable属性创建类似web编辑器的wordpress 在已调整contenteditable的元素中按enter键,可以创建div标记。 div标记的字符是我想确定它是否为空 这是我写的代码 <div class="c-contenteditable" contenteditable="true" id="js-editable"></div> //In this case, consol
<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);
}
});
当您在contenteditable属性中按enter键时,如何在div标记中获取字符串?使用jquery的wrap函数来包装内容。谢谢!对不起,我不懂如何使用jquery的wrap函数。