使用javascript与indeterminate实现三态checkbox

当checkbox的indeterminate设置为true的时候, input会变成灰色打勾的状态. IE一直支持此属性, 而Firefox却不支持.不过在最新的Firefox3.6中, 也开始支持这个属性了. 我们可以用简单的javascript来实现三态checkbox.

$("input:checkbox").live("click",function()
{
	if(this.getAttribute("checked") && !this.getAttribute("indeterminate"))
	{
		this.setAttribute("indeterminate", true);
		this.setAttribute("indeterminate-status", true);
		return false;
	}
	else if(!this.getAttribute("indeterminate") && this.getAttribute("indeterminate-status"))
	{
		this.setAttribute("checked", true);
		this.removeAttribute("indeterminate-status");
		return true;
	}
});

Leave a Reply

Your email address will not be published.


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">