<html>
<body>
<select onfocus='blur(this);'>
<option>Volvo</option>
<opti开发者_StackOverflow社区on>Saab</option>
<option>Mercedes</option>
<option>Audi</option>
</select>
</body>
</html>
In firefox this works fine. In IE8, by clicking repeatedly you can get the options to appear. What gives? Anything else I can do to get the select to be readonly without showing it as disabled?
it would be onfocus="this.blur()"
but why would you do this? Just disable it. If you need the value, copy it to a hidden field
UPDATE:
<script>
function changeSel(idx) {
var sel = document.forms[0].sel;
sel.selectedIndex=idx;
sel.form.selCopy.value=idx;
}
window.onload=function() {
changeSel(document.forms[0].sel.selectedIndex);
}
</script>
<form>
<input type="text" name="selCopy" value="not set" />
<select name="sel" size="1" disabled="disabled">
<option>Zero</option>
<option>One</option>
<option selected>Two</option>
<option>Three</option>
<option>Four</option>
</select>
<input type="button" onClick="changeSel(3)" value="Three" />
</form>
You might want to go here: HTML form readonly SELECT tag/input
精彩评论