`

IE8/IE7/IE6下Select列表中disabled的使用

阅读更多
昨天项目中使用select列表list-to-list,其中右边有一项是不可以让用户选中,就是必须选,我使用了selectedFields.options[0].disabled = 'disabled';或者selectedFields.options[0].disabled = true;在IE8下面是正常的,不可选的,但在IE6和IE7下没有起到作用,试了几种方法都不行,最后在网上找到下面代码,只要copy到你的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++) {
if(select.id == "your select id") {[//你的select id
select.onfocus = function(){ window.select_current[this.id] = this.selectedIndex; }
				select.onchange = function(){ restore(this); }
				emulate(select);
			[color=red]}[/color]}
		}
	}
}

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";
		}
	}
}

分享到:
评论
2 楼 yaofeng911 2009-09-23  
f0799 写道
如果在select 中添加onchange="" 将会无效,请问怎么解决啊·~?如下代码
<select id="s1" onchange="alert(this.selectedIndex);">
  <option value="p1" >p1</option>
  <option value="p2" >P0</option>
  <option value="p3" >P3</option>
  <option value="p4" >P4</option>
</option>
onchange方法被select-option-disabled-emulation.js代码中select.onchange = function(){ restore(this); } 覆盖

你要使用onchange事件是话,可能只有把select-option-disabled-emulation.js代码换成其它事件类似替代它。可以试试看先...
1 楼 f0799 2009-09-23  
如果在select 中添加onchange="" 将会无效,请问怎么解决啊·~?如下代码
<select id="s1" onchange="alert(this.selectedIndex);">
  <option value="p1" >p1</option>
  <option value="p2" >P0</option>
  <option value="p3" >P3</option>
  <option value="p4" >P4</option>
</option>
onchange方法被select-option-disabled-emulation.js代码中select.onchange = function(){ restore(this); } 覆盖

相关推荐

    IE6中select标签的option不能disabled的解决方案

    下载select-option-disabled-emulation.js文件即可自动完成disabled标记的工作

    select-option-disabled-emulation.zip_OPTION_select option_select

    select-option-disabled-emulation.js解决IE6 Select 中 option 的disabled属性无效的办法~~~在页面加载时架子该js,呵呵有点问题:onchange 时间冲突 自己改改··

    SELECT在浏览器中相关Bug整理

    在IE7及以下 虽然disabled 对 select能起作用,但对select下的option却无效。 解决方法通常是判断浏览器,如果是IE7以下的话,则当change和focus时改变option颜色和并且点击“无效”的option后 select选中的项值不...

    js使用小技巧

    无关闭按钮IE window.open("aa.htm", "meizz", "fullscreen=7"); 统一编码/解码 alert(decodeURIComponent(encodeURIComponent("http://你好.com?as= hehe"))) encodeURIComponent对":"、"/"、";" 和 "?"也编码 ...

    ExtAspNet v2.2.1 (2009-4-1) 值得一看

    -重命名AccordionPanel为AccordionPane (这也是在Asp.net AJAX中使用的名称). +所有的面板默认有两个集合属性(Toolbars和Items). -尽管TabStrip, From, Tree, Accordion继承了Items属性,但是你并不能对其设置...

    IBM WebSphere Portal门户开发笔记01

    1)在定制主题和外表中使用拖放 85 2)拖放标记摘要 85 3)拖放 API 86 八、功能应用或问题 87 1、WCM多子站区指向指定子站区配置 87 2、更改PORTAL默认的登录选项 89 3、如何在主题与皮肤中获取PORTAL登录用户信息 ...

    ExtAspNet_v2.3.2_dll

    -重命名AccordionPanel为AccordionPane (这也是在Asp.net AJAX中使用的名称). +所有的面板默认有两个集合属性(Toolbars和Items). -尽管TabStrip, From, Tree, Accordion继承了Items属性,但是你并不能对其设置...

    ICS delphixe10源码版

    ICS - Internet Component Suite - V8 - Delphi 7 to RAD Studio 10 Seattle ======================================================================= (Aka FPIETTE's Components) Revised: March 3, 2016 ...

    JS分页效果JS分页效果

    .pages select, .pages input { color: #000000; font-size: 10px; font-family: Tahoma, Verdana; } /* Mode 5 Style (Input) */ .pages .input input.ititle, .pages .input input.itext, .pages .input input....

    html入门到放弃笔记

    4、style :定义 内联方式方式使用(CSS中) 4、注释 语法:&lt;!-- --&gt; 注意: 1、注释不能嵌套 2、注释不能出现在标记中 3、HTML 文档结构 W3C :Word Wide Web Consortium (万维网联盟) 1、HTML文档的...

    javascript函数的解释

    84.JS中的模态显示在IE4+行,在NN中不行:showModalDialog("URL"[,arguments][,features]); 85.JS中的退出之前使用的句柄:function verifyClose(){event.returnValue= "we really like you and hope you will stay ...

    107个常用javascript语句

    84.JS中的模態显示在IE4 行,在NN中不行:showModalDialog("URL"[,arguments][,features]); 85.JS中的退出之前使用的句柄:function verifyClose(){event.returnValue="we really like you and hope you will stay ...

    jQuery完全实例.rar

    返回 'true' 跳至下一个循环(就像在普通的循环中使用'continue')。 -------------------------------------------------------------------------------- Execute a function within the context of every matched...

    计算机应用技术(实用手册)

    列表中存在PRIMARY MASTER 第一组IDE主设备;PRIMARY SLAVE 第一组IDE从设备;SECONDARY MASTER 第二组IDE主设备;SECONDARY SLAVE 第二组IDE从设备。这里的IDE设备包括了IDE硬盘和IDE光驱,第一、第二组设备是指...

    layui前端框架-其他

    不再是只对输入框自动获焦定位 &lt;/p&gt;[加强] form 组件对 url 的验证&lt;/p&gt;[修复] form 相关 css 的 layui-checkbox-disabled 书写错误(之前为 disbaled) &lt;/p&gt;[修复] form 组件的 select option 内容出现换行时的...

    jQuery中操控hidden、disable等无值属性的方法

    一般我们在实现一些表单提交页面时会放置若干隐藏属性 比如在修改某条记录时,在编辑窗口会嵌入该记录的id 在展示界面有时需要将input或select选框设为disable以避免用户修改 下列代码中的hidden在IE中不能正常作用 ...

    IBM3650M4驱动

    IBM ServeRAID-MR10ie (CIOv) SAS Controller for BladeCenter (46C7167) IBM ServeRAID MR10is SAS Controller (44E8695) IBM ServeRAID MR10il SAS Controller (44E8767) IBM ServeRAID MR10M SAS Controller ...

    BURNINTEST--硬件检测工具

    test phase" was selected the DTR and RTS lines would be explicitly disabled to prevent any toggling of these lines. Previously these where enabled, but not explicitly toggled. Release 5.3 build ...

    ImpREC 1.7c

    - Fixed bug on disabled editboxes (you could edit them.... erm) - Added checks in PEFile.cpp for invalid executables (Thanks to Snacker!) - Fixed some possible problems on sscanf and ordinals ("%X...

    jQuery 1.5 API 中文版

    IE用户无法在线查看本文档,请下载jQuery API Version1.5 中文版AIR客户端查看,或者使用chrome,safari,firefox,opera等浏览器查看!!! jQuery 1.5 API Cheat Sheet来源 Selectors Basics #id element .class, ...

Global site tag (gtag.js) - Google Analytics