在keyup / keypress事件中用标记包装来自的行
在
键入内容时,如果没有用
标记包装,请查找该行是否有
标记。 如果标题标记出现,则不应使用
标记包装它。
在谷歌浏览器浏览器中,添加标题标记内容后,而不是使用
标记包装内容,使用
包装它。 怎么预防这个?
我的代码:
var timeoutReference; $("#edited_content").keyup(function(e) { var code; code = (e.keyCode ? e.keyCode : e.which); if (code === 13) { $("#edited_content").contents().filter(function() { return this.nodeType === 3 && $.trim(this.nodeValue).length; }).wrap(""); } else { if (timeoutReference) { clearTimeout(timeoutReference); } timeoutReference = setTimeout(function() { $("#edited_content.publitory").contents().filter(function() { return this.nodeType === 3 && $.trim(this.nodeValue).length; }).wrap(""); }, 3000); } });
在开始输入时,用
标签包装当前行并输入,然后下一行应该用
标签包装。 在我的代码中,我做了setTimeout
3秒,如果停止键入3秒,然后用
标签包装该行。 但我的客户要求删除setTimeout
,他想立即用
包装当前行。 怎么做到这一点?
输入html内容:
test content sub content
content1
用
标签包装之后得到的html内容:
Test content
sub content
content1
但在Chrome浏览器中:
test content
sub content
content1