因为Select下拉框只支持disabled属性,不支持readOnly属性,
但是用disabled就无法将下拉框中的数据读出来,所以要想办法将select下拉框设置成只读的。
将select下拉框设置成readonly 的两种办法。
第一种:
<script>var f=s.selectedIndex</script> <select name=s onchange="selectedIndex=f"> <option>1 </option> <option selected>2 </option> </select>
第二种:
<span onmousemove="this.setCapture();" onmouseout="this.releaseCapture();" onfocus="this.blur();"> <select > <option>1 </option> <option selected>2 </option> </select> </span>
其中onmousemove="this.setCapture();" onmouseout="this.releaseCapture();" 屏蔽了鼠标事件,
onfocus="this.blur();"屏蔽了键盘事件,onfocus="this.blur();"表示该对象将获得焦点时就让它失去焦点,按 键盘的TAB键时跳过它,使下一个控件获得焦点。
在网上搜索了一下,发现有个一下类似的方法:
①
<select name="select123" onbeforeactivate="return false;" onfocus="this.blur();" onmouseover="this.setCapture();" onmouseover="this.releaseCapture();"> <option>aaa</option> </select>
②或者使用如下的js脚本:
<select name="select123"> <option>aaa</option> </select> <script type="text/javascript"> SetReadOnly(document.getElementById("select123")); function SetReadOnly(obj){ if(obj){ obj.onbeforeactivate = function(){return false;}; obj.onfocus = function(){obj.blur();}; obj.onmouseover = function(){obj.setCapture();}; obj.onmouseout = function(){obj.releaseCapture();}; } } </script>
①②使用起来相对于不太好用,文章前者更实用。
相关推荐
NULL 博文链接:https://shirleyit.iteye.com/blog/718633
js 操作select 下拉框js 操作select 下拉框
尽管现在的浏览器更新换代后更加强大,浏览器默认控件也逐渐变得美观起来,特别是Select下拉框,已经不再是以前IE6那样的丑陋了。但是今天我们要为大家分享一款基于jQuery的Select下拉框美化插件,它完全重写了...
当下拉菜单选项比较多的时候,select下拉列表内容过多,在IE中默认是30条选项,firefox默认是20条, 超过自动出现滚动条,但是在没出现滚动条时候样式特别不...本次上传的代码将提供一种方法将select下拉框添加滚动条
select 下拉框可以多选Demo事列.
bootstrap-select 下拉框demobootstrap-select 下拉框demobootstrap-select 下拉框demobootstrap-select 下拉框demobootstrap-select 下拉框demobootstrap-select 下拉框demobootstrap-select 下拉框demobootstrap-...
html最全的js javascript操作select 下拉框
jQuery select下拉框美化代码基于jquery.1.10.2.min.js制作,点击下拉框,显示下拉框内容。
select下拉框支持搜索【中文搜索】文件
里面提供 并解决所有获得select下拉框里面的值 很有帮助
带搜索功能的select下拉框,类似百度google的搜索框,自己匹配,很好用
jQGrid动态填充select下拉框的选项值(动态填充)
select下拉框,按下空格键后让它的选项显示出来,按回车键选中值
jQuery Editable Select 是一个jQuery插件,它将选择转换成输入字段,其中根据输入的字符实时显示单个元素。当JavaScript不可用时,它就变成了一个真正的选择列表。
下载后直接解压查看源文件,文件是html 直接双击打开查看效果
一组经过美化的jQuery select下拉框单选和多选插件,带搜索功能,模拟select下拉框多选菜单选择效果。
下拉框的option没有value属性时 代码如下: <select id=”param1″> 学号</option> 姓名</option> 年龄</option> </seclect> [removed] [removed] = funciton(){ var param = document.getElementById(“param1...
select下拉框可编辑输入框 select下拉框可编辑输入框 select下拉框可编辑输入框
select美化下拉框美化select美化下拉框美化select美化下拉框美化select美化下拉框美化select美化下拉框美化
好看的select下拉框(带搜索功能),由于默认select样式过丑而且有些东西还不好改,这个是利用input框和ul来实现一个下拉框的效果。分为不带搜索功能和带搜索功能两个部分。以及jquery与javascript两种实现