Use JS to set the Drop-down box for read-only tips

Source: Internet
Author: User

 select does not have a read-only property, so you need to include a span outside of the select, which can be changed by JS, and you need a friend to refer to the following

In the project development process we often encounter to set the Drop-down box read-only (ReadOnly), but unfortunately the select has no read-only attribute, so you need to include a span outside the select, through JS to change.     The following HTML code adds a span tag to the STRUTS2 drop-down tab and makes the dropdown box unreadable when the page is loaded.   Code as follows: <body onload= "init ()" >  <span id= "Id_select" >  <s:select name= "SJDWMC" list= " Sjdxdwlist "listkey=" Dxbh "listvalue=" DWMC "headerkey=" "headervalue=" "></s:select>  </span>   </body>    The following is the JS code, called Selectreadonly in the Init method to make the Drop-down box read-only.     Code as follows:/* Set Select to read-only/    function selectreadonly (selectedid) {  var obj = based on the ID of the span on the page 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"); }    Do this here, try the effect!!!  

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.