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.
Copy Code code as follows:
<body onload= "init ()" >
<span id= "Id_select" >
<s:select name= "SJDWMC" list= "sjdxdwlist" listkey= "Dxbh" listvalue= "DWMC" "headerkey=" "headervalue=: Select>
</span>
</body>
The following is the JS code, called Selectreadonly in the Init method to make the Drop-down box read-only.
Copy Code code as follows:
/* Set Select to read-only based on the ID of span 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");
}
Do this here, try the effect of it!!!