Home > Web Front-end > JS Tutorial > body text

js implements the focus in the last position of the text box_javascript skills

WBOY
Release: 2016-05-16 16:57:26
Original
1052 people have browsed it

In general programs, programmers generally like to determine the focus box by judging the legality of the content when checking the correctness of the content of the input box.

For example:

Copy code The code is as follows:

if(obj.value== ""){
obj.focus();
return false;
}

In this way, when an input box is empty, the focus will be moved to that input Frame..This function is very convenient to use..but there is a small problem...

That is, after obj.focus() moves the focus to the input box, it will move the text cursor (that is, the flashing vertical line) to the position of the first character of the input box... Just above In terms of judgment...if there is no content in the text box...obj.focus can just allow us to enter content directly in the text box without clicking the text box to make the text focus...

However, if there is already content in the text box... but this content is illegal. obj.focus() also moves the cursor to the position of the first character of the text box... At this time, attention will be drawn The user experience designer is frustrated... What we need is that the text box gets focus, and then the text cursor moves to the end of the text box, so that the user can enter content directly without clicking the text box. The input content will be in the original content. Add them later...

The following code can complete this small detail:

Copy the code The code is as follows:



This code will be of great help to designers in the details of user experience...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template