简体   繁体   English

加入 <br/> 当用户在jQuery中按Enter键时,p TAG内容可编辑

[英]adding <br/> to p TAG contenteditable when user press enter key in jquery

How can I add a <br/> to <p contenteditable> when the user press the Enter key in jQuery or javascript? 当用户按jQuery或javascript中的Enter键时,如何在<p contenteditable>添加<br/>

I tried every solution with no happy ending. 我尝试了每一个解决方案都没有圆满的结局。 A div element is always showing. div元素始终显示。

Currently trying on Chrome browser. 目前正在Chrome浏览器上尝试。

This is the solution for now: 这是目前的解决方案:

$(this).val($(this).val() + "\n");
setTimeout(function(){
    $($editedDiv).html($('.ui-selected').html().replace(/<div>(.*?)<\/div>/, "<br>$1"));
},100);

The problem with this solution is that tha caret location is moving to the start of the sentence when i press Enter 此解决方案的问题是,当我按Enter键时,插入符号的位置将移动到句子的开头

This answer may be helpful. 这个答案可能会有所帮助。 Of course, with more details, like which browsers you're having issues in (and maybe some code), we could help you pinpoint the exact problem. 当然,有了更多详细信息,例如您遇到哪些浏览器问题(可能还有一些代码),我们可以帮助您确定确切的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM