JavaScript (JS) Setting default input focus (focusing) _javascript tips

Source: Internet
Author: User
This feature is often used in replies and references, that is, clicking a reply or reference, such as having the input focus appear in the message input box, and if the anchor is used to locate, the input focus cannot be activated.
Copy Code code as follows:

JAVASCRIPT:DOCUMENT.GETELEMENTBYID ("id"). focus ();
or Javascript:document.all.id.focus ();
or Javascript:document.all.name.focus ();

Example
Copy Code code as follows:

<input type= "text" Name= "tt" id= "tt" >
<input type= "button" Name= "BT" id= "onclick=" Javascript:document.all.tt.focus (); "value=" to set focus on text box ">

Take a closer look at the responses and references used by this blog and how the focus is positioned to the right of the text.
Copy Code code as follows:

//reference Call function
Function quote (name,id) {
var quotemsg=document.getelemen Tbyid (ID). InnerHTML;
var Content=document.getelementbyid ("comment");
Quotemsg=quotemsg.replace (//g," ~^ "). Replace (/<br>/g, ' n ');
Content.focus ();//To get focus to the right of the text, this line of code is preceded by
content.value=quotemsg+ ' +name+ ' + ' n ' + ' —————————————————————— ' + ' n '; Fill in the text
return false;//Cancel the effect of href
}
//Reply to auto-enter name function
function backcomment (msg) {
Backdb=document. getElementById (' comment ');
Backdb.focus ();
backdb.value=msg+ ' n ';
return false;
//return true; original anchor to locate
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.