停止插入符号跳到文本区域的底部?
我有一个文本区域,里面有很多文本,并且我有代码,这样当您按 Shift+Enter 时,它将插入一段文本。然而,目前,一旦发生这种情况,文本就会滚动,以使插入符号出现在屏幕底部。
我的插入代码:
$("#body textarea").bind('keydown', function(event) {
var caret = $("#body textarea").caret();
if(event.keyCode == 13 && event.shiftKey)
{
var text = "[br]"
insertText("#body textarea", caret.start, caret.end, text, "");
$("#body textarea").caret(caret.start+(text.length), caret.start+(text.length));
}
});
有谁知道我能做什么来阻止它强制插入符到底部?
干杯
黑幽灵
I have a textarea with a lot of text in it, and I have code so that when you press Shift+Enter, it will insert a piece of text. However, at the moment, as soon as that happens, the text scrolls so that the carets at the bottom of the screen.
My insert code:
$("#body textarea").bind('keydown', function(event) {
var caret = $("#body textarea").caret();
if(event.keyCode == 13 && event.shiftKey)
{
var text = "[br]"
insertText("#body textarea", caret.start, caret.end, text, "");
$("#body textarea").caret(caret.start+(text.length), caret.start+(text.length));
}
});
Does anyone know what I can do to stop it forcing the caret to the bottom?
Cheers
BlackWraith
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 stackoverflow.com 上发现同样的麻烦并做出为您提供样品
http://jsfiddle.net/deerua/WAZBQ/
I found on stackoverflow.com same trouble and make sample for you
http://jsfiddle.net/deerua/WAZBQ/
您可以在插入文本后手动设置插入符位置:
请参阅 http://blog.vishalon.net/index.php/javascript-getting-and-setting-caret-position-in-textarea/:
ctrl是您的文本区域元素。
You can set the Caret Position manually after inserting your text:
See http://blog.vishalon.net/index.php/javascript-getting-and-setting-caret-position-in-textarea/:
ctrl is your textarea-element.