如何在文本区域的末尾设置光标? [英] How to set cursor at the end in a textarea?

查看:51
本文介绍了如何在文本区域的末尾设置光标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 textarea 元素的末尾设置光标?我使用的是Firefox 3.6,不需要在IE或Chrome中运行.似乎这里所有相关的答案都使用 onfocus()事件,该事件似乎没有用,因为当用户单击 textarea 元素内的任何位置时,Firefox会将光标位置设置在该位置.我要在 textarea 中显示一个长文本,以便显示最后一部分(使在末尾添加内容更容易).

Is there a way to set the cursor at the end in a textarea element? I'm using Firefox 3.6 and I don't need it to work in IE or Chrome. It seems all the related answers in here use onfocus() event, which seems to be useless because when user clicks on anywhere within the textarea element Firefox sets cursor position to there. I have a long text to display in a textarea so that it displays the last portion (making it easier to add something at the end).

没有框架或库.

推荐答案

可能有很多方法,例如

element.focus();
element.setSelectionRange(element.value.length,element.value.length);

> http://jsfiddle.net/doktormolle/GSwfW/

这篇关于如何在文本区域的末尾设置光标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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