Tips for setting the drop-down box to read-only using js _ javascript skills

Source: Internet
Author: User
Select has no read-only attribute. Therefore, you need to include a span outside the select statement and change it through js, for more information, see the following: during project development, we often encounter the need to set the drop-down box to read-only, but unfortunately the select statement does not have the read-only attribute, therefore, you need to include a span outside the select statement and change it through js.

The following html code adds the span tag to the struts2 drop-down label. when loading the page, the drop-down box becomes unreadable.

The Code is as follows:








The following is the js Code. Call selectReadOnly In the init method to make the drop-down box read-only.

The Code is as follows:


/* Set select to read-only based on the span id on the page/

Function selectReadOnly (selectedId ){
Var obj = document. getElementById (selectedId );
Obj. onmouseover = function (){
Obj. setCapture ();
}
Obj. onmouseout = function (){
Obj. releaseCapture ();
}
Obj. onfocus = function (){
Obj. blur ();
}
Obj. onbeforeactivate = function (){
Return false;
}
}

Function init (){
SelectReadOnly ("id_select ");
}


Let's make a try !!!

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.