打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
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就可以做到不可选的效果了。
有用到可以看看:
Javascript代码 
/****************************************************************
* 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";
}
}
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
jquery获得option的值和对option进行操作
HTML中的<select>标签如何设置默认选中的选项
Jquery和javascript常用技巧
jQuery-对Select的操作集合[终结篇] - 博客文库 - 博客园
2014.3.27
js中,两种获得选中Option的方法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服