how to prevent the cursor from jumping to next line in textarea using jquery

血红的双手。 提交于 2019-12-12 02:53:28

问题


I am working on TinyMCE editor where I have to customize it for some special equation. The problem is that when I press the enter key, the cursor goes to new line. My question is how to prevent the cursor from jumping to new line when someone press the enter key inside the editor.I want to cursor to remain where it is before, on pressing the enter key. Just like textarea, when the enter key is pressed, the cursor goes to new line. Can anyone explain how to prevent the cursor from jumping to new line.

Thanks.


回答1:


I think you can capture the Enter key by using

$(document).keypress(function(e) {
  if(e.which == 13) {
    // enter pressed
  }
});

This will capture the key in the whole document though



来源:https://stackoverflow.com/questions/18935913/how-to-prevent-the-cursor-from-jumping-to-next-line-in-textarea-using-jquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!