如何使用jquery防止光标跳至textarea中的下一行 [英] how to prevent the cursor from jumping to next line in textarea using jquery

查看:137
本文介绍了如何使用jquery防止光标跳至textarea中的下一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TinyMCE编辑器,在其中必须针对一些特殊方程式对其进行自定义.问题是,当我按Enter键时,光标移至新行.我的问题是当有人在编辑器中按Enter键时如何防止光标跳到新行.我想在按Enter键时将光标保留在之前的位置.就像textarea一样,当按下Enter键时,光标会移至新行.谁能解释一下如何防止光标跳到新行.

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.

谢谢.

推荐答案

我认为您可以使用来捕获Enter键

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

这篇关于如何使用jquery防止光标跳至textarea中的下一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆