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

The focus() function in jquery automatically moves the cursor to the end of the content when the object gains focus_jquery

WBOY
Release: 2016-05-16 17:21:04
Original
1296 people have browsed it
Copy code The code is as follows:

setFocus=function(id){
var t=$( "#" id).val();
$("#" id).val("").focus().val(t);
}

Put The focus cursor moves to the end of the id text.

After jquery gets focus, the cursor is behind the string. When input gets focus, it automatically moves the cursor to the end of the text content. jQuery uses focus() to focus the text input box and the focus is on the rightmost side of the text. Method
Copy code The code is as follows:

//The cursor is after the string after getting focus
//The principle is to copy and paste yourself again after getting the focus
var t=$("#" id).val();
$("#" id).val(" ").focus().val(t);
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