javascript Disable <div> or other tag in Other Browser like FF,Chrome

如果你也和我一样,不幸维护了一个javascript,它广泛的在非input,textbox,等html标签才有xxx.disable=true.功能.这段代码并不幸地要兼容其他非IE浏览器,也许下面这段脚本对你有用:

 

 

function IsIE()
{
	return !!(window.attachEvent && !window.opera)
}
function setDisabled(el, disabled){
	if(IsIE())
	{
		el.disabled=disabled;
	}
	else
	{//非IE浏览器中.把onclick等属性挪一下再挪回来
		if(disabled)
		{
			el.__onclick=el.onclick;
			el.onclick=" ";
			el.__onmouseover=el.onmouseover;
			el.onmouseover=" ";
			el.__onmouseout=el.onmouseout;
			el.onmouseout="";
		}
		else{
			if(el.__onclick)
				el.onclick=el.__onclick;
			if(el.__onmouseover)
				el.onmouseover=el.__onmouseover;
			if(el.__onmouseout)
				el.onmouseout=el.__onmouseout;				
		}
		el.disabled=disabled;
	}
}


剩下就就是这种方法没有灰显的效果,交给css吧.

posted on 2010-12-30 14:50  Haozes  阅读(793)  评论(0编辑  收藏  举报