This function is often used in reply and reference, that is, click reply or reference. For example, if the input focus is displayed in the message input box, if you use an anchor to locate the input focus, the input focus cannot be activated.
Copy codeThe Code is as follows: javascript: document. getElementById ("id"). focus ();
Or javascript: document. all. id. focus ();
Or javascript: document. all. name. focus ();
Example:Copy codeThe Code is as follows: <input type = "text" name = "tt" id = "tt">
<Input type = "button" name = "bt" id = "bt" onclick = "javascript: document. all. tt. focus (); "value =" set focus for text box ">
Next, let's take a look at the location of the reply and reference used in this blog, and how to locate the focus on the right side of the text.Copy codeThe Code is as follows: // reference the call Function
Function quote (name, id ){
Var quoteMsg = document. getElementById (id). innerHTML;
Var content = document. getElementById ("comment ");
QuoteMsg = quoteMsg. replace (//g ,"~ ^ "). Replace (/<BR>/g, 'n ');
Content. focus (); // to focus on the right side of the text, this line of code should be in front
Content. value = quoteMsg + '[Reference' + name + ']' + 'n' + '--------------------' + 'n' '; // enter the text
Return false; // The role of canceling href
}
// Reply to the automatically input name Function
Function backcomment (msg ){
Backdb = document. getElementById ('comment ');
Backdb. focus ();
Backdb. value = msg + 'n ';
Return false;
// Return true; originally positioned with an anchor
}