阻止contentEditable中的行/段落 [英] Prevent line/paragraph breaks in contentEditable
问题描述
在Firefox中使用contentEditable时,有没有办法阻止用户通过按Enter或Shift + Enter来插入段落或换行符?
您可以将事件处理程序附加到contentEditable字段的keydown或keypress事件,如果键码自身标识为enter(或shift + enter),则可以取消该事件。
如果焦点位于contentEditable字段,则会禁用enter / shift +完全输入。
如果使用jQuery,如下所示:
$(#idContentEditable).presspress(function(e){return e.which!= 13;});
...将在返回时返回false并取消按键事件。
When using contentEditable in Firefox, is there a way to prevent the user from inserting paragraph or line breaks by pressing enter or shift+enter?
You can attach an event handler to the keydown or keypress event for the contentEditable field and cancel the event if the keycode identifies itself as enter (or shift+enter).
This will disable enter/shift+enter completely when focus is in the contentEditable field.
If using jQuery, something like:
$("#idContentEditable").keypress(function(e){ return e.which != 13; });
...which will return false and cancel the keypress event on enter.
这篇关于阻止contentEditable中的行/段落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!