给IE下的option项添加disabled的禁用功能
window.onload = function() {
if (document.getElementsByTagName){
var s = document.getElementsByTagName("select");
if (s.length > 0){
window.select_current = new Array();
for (var i=0, select; select = s[i]; i++){
select.onfocus = function(){
window.select_current[this.id] = this.selectedIndex;
}
select.onchange = function(){
restore(this);
}
emulate(select);
}
}
}
}
function restore(e){
if (e.options[e.selectedIndex].disabled){
e.selectedIndex = window.select_current[e.id];
}
}
function emulate(e){
for (var i=0, option; option = e.options[i]; i++){
if (option.disabled){
option.style.color = "graytext";
}else{
option.style.color = "menutext";
}
}
}
select只读模式
1.disabled:方便,但在表单提交时无法获得值
<select name="" disabled="disabled">
<option>哎,禁用了啊。</option>
<option>没用的选项。</option>
</select>
2.给出默认值,改变选项时自动变回默认选项
<select name="select" onchange="selectedIndex=0">
<option>abc</option>
<option>def</option>
</select>
3.使用optgroup元素
<select>
<option selected>下面两项只能看看啊</option>
<optgroup label="看看一">
</optgroup>
<optgroup label="看看二,哈哈">
</optgroup>
</select>
参考内容:
1.http://www.cainiao8.com/web/js_blueidea/32_readonly_select.html
2.http://blog.csdn.net/fableking/archive/2008/01/31/2075881.aspx
分享到:
相关推荐
author:咔咔 wechat:fangkangfk 前端代码 js代码 ... $('select').attr('disabled', 'disabled'); form.render('select'); } } // 禁止select点击 disSelect(); 以上这篇Layui 动态禁止selec
今天小编就为大家分享一篇layui select 禁止点击的实现方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
1、编写一对 body 标记,在body标记中,嵌套一对 div标记,在 div 标记中 ,嵌套一对 a 标记,在 a标记中,嵌套一对 b 标记,b标记中,随意编写一些文本 <body> 这是一段测试文本 </body> ...
select option 内容出现换行时的样式异常问题</p><p>[修复] colorpicker 颜色选择组件在 Firefox 下选择颜色时的若干兼容问题</p><p>[加强] colorpicker 组件的坐标定位计算方式</p><p>[修复] 低版本 ie 若干报错...
<input style="ime-mode:disabled"> 自动全选 <input type=text name=text1 value="123" onfocus="this.select()"> ENTER键可以让光标移到下一个输入框 (event.keyCode==13)event.keyCode=9"> 文本框的默认值...
在正则表达式中,括号的第二个用途是在完整的模式中定义子模式。当一个正则表达式成功地和目标字符串相匹配时,可以从目标串中抽出和括号中的子模式相匹配 的部分.例如,假定我们正在检索的模式是一个或多个字母后面...
后面是IDE设备的类型和硬件参数,TYPE用来说明硬盘设备的类型,我们可以选择AUTO、USER、NONE的工作模式,AUTO是由系统自己检测硬盘类型,在系统中存储了1-45类硬盘参数,在使用该设置值时不必再设置其它参数;...
若要用到聊天、语音聊天、传送信息等连接模式,必须将相应的8个dll文件也拷贝到该目录中:ChatLPCx.dll、raudiox.dll、rchatx.dll、unicows.dll、vcintcx.dll、vcintsx.dll、voicex.dll、WinLpcDl.dll。 (3)、...
若要用到聊天、语音聊天、传送信息等连接模式,必须将相应的8个dll文件也拷贝到该目录中:ChatLPCx.dll、raudiox.dll、rchatx.dll、unicows.dll、vcintcx.dll、vcintsx.dll、voicex.dll、WinLpcDl.dll。 (3)、...
用于弹出一个消息框 第二章 图形输出 2.1 和GUI有关的各种对象 在Windows中有各种GUI对象(不要和C++对象混淆),当你在进行绘图就需要利用这些对象。而各种对象都拥有各种属性,下面分别讲述各种GUI对象和拥有的...