原文:
Select, Option, Disabled And The JavaScript Solution
今天在工作中需要用到disabled掉一些select的option,结果发现IE6没有实现它。
还好我们下载select-option-disabled-emulation.js文件即可自动完成disabled标记的工作,代码也很少:
/****************************************************************
* Author: Alistair Lattimore
* Website: http://www.lattimore.id.au/
* Contact: http://www.lattimore.id.au/contact/
* Errors, suggestions or comments
* Date: 30 June 2005
* Version: 1.0
* Purpose: Emulate the disabled attributte for the <option>
* element in Internet Explorer.
* Use: You are free to use this script in non-commercial
* applications. You are however required to leave
* this comment at the top of this file.
*
* I'd love an email if you find a use for it on your
* site, though not required.
****************************************************************/
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-option-disabled-emulation.js文件即可自动完成disabled标记的工作
select-option-disabled-emulation.js解决IE6 Select 中 option 的disabled属性无效的办法~~~在页面加载时架子该js,呵呵有点问题:onchange 时间冲突 自己改改··
select下拉框不可编辑,但可以传值到后台
Select2Buttons是一个能将网页中的select选择框转换成一组按钮的插件。 主要功能特点: 转换select选择框为标签式按钮 支持js回发调用 支持disabled选项 支持将多个select设置为一组 支持取消默认...
方法如下: 代码如下:<select onbeforeactivate=”return false” onfocus=”this.blur()” onmouseover=”this.setCapture()” onmouseout=”this.releaseCapture()... <option>1</option> </select>
在IE7及以下 虽然disabled 对 select能起作用,但对select下的option却无效。 解决方法通常是判断浏览器,如果是IE7以下的话,则当change和focus时改变option颜色和并且点击“无效”的option后 select选中的项值不...
本篇文章是对js disabled="false"不起作用的解决办法进行了详细的分析介绍,需要的朋友参考下
JavaScript三级联通实现最新全国各省、市、县联动Select脚本,数据为最新全国全国各省、市、县数据,纯JavaScript实现。 部分代码如下: //这是从国家统计局网站下载的全国行政区划代码,先把他转化为JSON对象, //...
disabled属性disabled属性disabled属性disabled属性disabled属性disabled属性
设置了disabled属性后,后台读取不到数据,让select支持readonly属性,可以设置disabled属性,并把表单值存入hidden隐藏域中,也可以使用jquery控制。示例如下,需要的朋友不要错过
交换机端口状态出现err_disabled的情况分析与解决方法.doc
author:咔咔 wechat:fangkangfk 前端代码 js代码 ... $('select').attr('disabled', 'disabled'); form.render('select'); } } // 禁止select点击 disSelect(); 以上这篇Layui 动态禁止selec
Android studio 启动模拟器时解决 VT-x is disabled in BIOS的问题
form表单中的Input使用disabled导致不能提交,经测试终有一解,具体如下,希望遇到类似问题的朋友可以参考下,希望对大家有所帮助
Ewebeditor License not found. Disabled.doc
Readonly只针对input(text/ password)和textarea有效,而disabled对于所有的表单元素都有效,包括select,radio, checkbox, button等。 但是表单元素在使用了disabled后,当我们将表单以POST或GET的方式提交的话,这...
在html标签中设置按钮被禁用,可以使用如下代码 <input type=’button’ id=’test’ value=’disabled’> 在jquery中可以使用attr()函数修改按钮的disable属性 $(“#test”).attr(‘disabled’,false); ...
el-select 如下源码中 tag closable 属性为 el-select 的 disabled 属性,所有明显不支持。 解决思路(从el-select 的角度来考虑,其他组件组合的情况暂不考虑) 想要实现某些选项是不删除,1、需要tag 不可删除,2...
Ant design vue 的组件禁用属性 disabled