开发者

showing the end of a textfield

I have a bunch of textfields which identical starting data, the first 2 dozen characters are all the same for every input.

The end is different.

开发者_如何学GoHow do I get the textfield to scroll right automatically to show the end by default?


@el toni has a great solution. However, the textfield won't function properly if the user is required to input any text. (The cursor will jump to the left.)

<input dir="rtl" value="https://stackoverflow.com/questions/1962168/scroll-to-the-very-right-of-a-long-text-input">

(*Above from "Scroll" to the very right of a long text input courtesy @el toni)

You could use some js so that when the user clicks on the field, the "right direction" for text input is re-established. Then change it back to the other direction after he/she clicks off.

 $("#longInput").focus(function () {
     $(this).attr('dir', 'ltr');
});
 $("#longInput").blur(function () {
     $(this).attr('dir', 'rtl');
});

http://jsfiddle.net/kjjL2/


You can try with the scrollTo javascript function:

var myTextfield = document.getElementById("myTextfield");
myTextfield.scrollTop = myTextfield.scrollHeight;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜