During the project development process, we often encounter the need to set the drop-down box to readonly, but unfortunately select does not have a read-only attribute, so we need to include a span outside the select and change it through js.
The following HTML code adds the span tag to the drop-down tag of struts2, which makes the drop-down box unreadable when the page is loaded.
The following is the js code. Call selectReadOnly in the init method to make the drop-down box become only read.
/*Set select to only based on the span id on the page Read/
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");
}
You are done here, try the effect! ! !