jQuery contenteditable换行符 [英] jquery contenteditable linebreak
本文介绍了jQuery contenteditable换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个内容可编辑的区域,并且我试图禁止回车和回车以创建新段落,我在下面的脚本中使用了此功能,但它同时禁用了所有按钮,我想做的是返回后只需放置一个换行符,然后再转到新段落即可.
I have a content editable area and I'm trying to disable enter/return and shift enter from creating a new paragraph, I have this working with the script below but it disables the buttons all together, what I wish to do is have return just place a line break rather then go to a new paragraph.
$("#content").keypress(function(e) {
return e.which != 13;
});
感谢所有帮助!
干杯
瓦扎
推荐答案
尝试如下操作:
$("#content").keypress(function(e) {
if (e.which == 13) {
e.preventDefault(); // I think this is the keyword you look for?
$("#content").val($("#content").val() + "<br/>"); // Handler for new p or line break etc.
}
});
这篇关于jQuery contenteditable换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文