Home > Web Front-end > JS Tutorial > Tips for setting the drop-down box to read-only using js_javascript tips

Tips for setting the drop-down box to read-only using js_javascript tips

WBOY
Release: 2016-05-16 16:52:59
Original
1480 people have browsed it

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.

Copy code The code is as follows:







The following is the js code. Call selectReadOnly in the init method to make the drop-down box become only read.
Copy code The code is as follows:

/*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! ! !
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template