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 !!!