Home > Web Front-end > JS Tutorial > JavaScript (js) sets the default input focus (focus)_javascript skills

JavaScript (js) sets the default input focus (focus)_javascript skills

WBOY
Release: 2016-05-16 17:45:04
Original
1048 people have browsed it

This function is often used in replies and quotes, that is, click the reply or quote. For example, if the input focus appears in the message input box, if anchors are used to position it, the input focus cannot be activated.

Copy code The code is as follows:

javascript:document.getElementById("id").focus ();
or javascript:document.all.id.focus();
or javascript:document.all.name.focus();

Example:
Copy code The code is as follows:




Let’s take a closer look at the positioning of replies and quotes used in this blog, and how to position the focus on the right side of the text.
Copy code The code is as follows:

//Quote calling function
function quote(name ,id){
var quoteMsg=document.getElementById(id).innerHTML;
var content=document.getElementById("comment");
quoteMsg=quoteMsg.replace(//g, "~^").replace(/
/ g,'n');
content.focus();//To have the focus on the right side of the text, this line of code must be in front
content.value=quoteMsg '[Quote' name ']' 'n ' '——————————————————————' 'n'; //Fill in the text afterwards
return false; //Cancel the function of href
}
//Reply the automatic name input function
function backcomment(msg){
backdb=document.getElementById('comment');
backdb.focus();
backdb.value= msg 'n';
return false;
//return true; Originally used anchor to position
}
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