用htc实现CHECKBOX控件

论坛 期权论坛 脚本     
niminba   2021-5-23 03:06   1344   0
复制代码 代码如下:

/*
描述:        CHECKBOX控件
版本:        1.1
备注:        CHECKBOX控件背后跟随的文字
            是获取CHECKBOX对象的htc_myLabel来显示的
            更新添加indeter属性,用来增加不确定的选择
*/
<public:component>
<public:attach event="oncontentready" onevent="fnInit()" />
<public:attach event="onpropertychange" onevent="fnPropertychange()" />
<script language="Javascript">
var checkBoxImg=window.document.createElement("IMG");
ImageArray=[];
ImageArray["checkbox_false"]="checkbox_false.gif";
ImageArray["checkbox_false_down"]="checkbox_false_down.gif";
ImageArray["checkbox_false_over"]="checkbox_false_over.gif";
ImageArray["checkbox_true"]="checkbox_true.gif";
ImageArray["checkbox_true_down"]="checkbox_true_down.gif";
ImageArray["checkbox_true_over"]="checkbox_true_over.gif";
ImageArray["checkbox_indeter"]="checkbox_indeter.gif";
ImageArray["checkbox_indeter_down"]="checkbox_indeter_down.gif";
ImageArray["checkbox_indeter_over"]="checkbox_indeter_over.gif";
function preLoad(path,obj){
    for(i in obj){
        this[i]=new Image();
        this[i].src=path+obj[i];
        }
    return this;
    }
preb=new preLoad("images/",ImageArray);
function fnInit(){
    var o=element;
    if(o.type=="checkbox"){
        var _table=window.document.createElement("TABLE");
        _table.cellSpacing="0px";
        _table.cellPadding="0px";
        _table.border="0px";
        if(o.disabled){
            _table.style.filter="alpha(Opacity=50)";
            }
        else{
            _table.style.filter="";
            }
        _table.style.display="inline";
        var _tr=_table.insertRow();
        var _td=_tr.insertCell();
        if (o.checked){
            checkBoxImg.src=preb["checkbox_true"].src;
            }
        else{
            checkBoxImg.src=preb["checkbox_false"].src;
            }
        if(o.indeter=="true"){
            o.indeterminate="true";
            checkBoxImg.src=preb["checkbox_indeter"].src;
            }
        _td.appendChild(checkBoxImg);
        _td=_tr.insertCell();
        _td.style.verticalAlign="bottom";
        if(o.htc_myLabel){
            _td.innerHTML="&nbsp<label style='cursor: hand'>"+o.htc_myLabel+"</label>";
            }
        o.insertAdjacentElement("afterEnd",_table);
        o.style.display="none";
        _table.attachEvent("onmouseover",function(){Baction("over")});
        _table.attachEvent("onmouseout",function(){Baction("out")});
        _table.attachEvent("onmousedown",function(){Baction("down")});
        _table.attachEvent("onmouseup",function(){Baction("up")});
        _table.attachEvent("onclick",function(){fnClick()});
        }
    }
function fnPropertychange(){
    var o=element;
&GR"f6'FWBòf6'6WCFb
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1060120
帖子:212021
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP