来源:ITPOW(www.itpow.com)
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>三态选择框</title> </head> <body> <div> <a href="http://www.itpow.com/" target="_blank">ITPOW www.itpow.com 专业探讨【ASP、JavaScript、XHTML+CSS、SQL Server】</a> <hr> </div> <div id="cb"></div> <div id="cb2"></div> <script language="javascript"> <!-- //三态选择框类 //checkBoxIdStr是用于承载选择框的HTML标签的ID //name三态选择框名称 //value三态选择框值,可选为:0-未选中,1-部分选中(或继承、无效),2-选中 //text选择框文字,支持HTML function CCheckBox(checkBoxIdStr) { this.checkBoxIdStr = checkBoxIdStr; this.checkBoxId = document.getElementById(this.checkBoxIdStr); this.name = ""; this.value = 0; this.text = ""; this.picDir = ""; this.Create = Create; this.ChngState = ChngState; } //创建三态选择框 function Create(name, value, text, objNameStr) { this.name = name; this.value = value; this.text = text; this.ChngState(this.value, objNameStr); } //更改三态选择框状态 function ChngState(value, objNameStr) { if (value == 0) { this.value = 0; } else if (value == 1) { this.value = 1; } else if (value == 2) { this.value = 2; } else { this.value = 0; } var index = this.value; var nextValue = (this.value<2)?(this.value+1):0; this.checkBoxId.innerHTML = "<input type=\"hidden\" name=\"" + this.name + "\" value=\"" + this.value + "\">" + "<img src=\"" + this.picDir + "cb_" + index + ".gif\"" + " onclick=\"javascript:" + objNameStr + ".ChngState(" + nextValue + ", '" + objNameStr + "');\">" + "<span style=\"cursor:default;\"" + " onclick=\"javascript:" + objNameStr + ".ChngState(" + nextValue + ", '" + objNameStr + "');\">" + this.text + "</span>"; } var objCB = new CCheckBox("cb"); objCB.picDir = "http://www.itpow.com/specials/jscomponent/images/cb/"; objCB.Create("c", 0, "是否订阅", "objCB"); var objCB2 = new CCheckBox("cb2"); objCB2.picDir = "http://www.itpow.com/specials/jscomponent/images/cb/"; objCB2.Create("c", 0, "是否订阅", "objCB2"); //--> </script> </body> </html> [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
创建于2005年 渝ICP备05010272号-1
电邮:cftea@126.com