国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > HTC > 正文

用htc實現CHECKBOX控件

2020-01-31 16:06:22
字體:
來源:轉載
供稿:網友
復制代碼 代碼如下:

/*
描述:        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=" <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;
    switch(event.propertyName.toString().toLowerCase()){
        case "checked":
            Baction("up");
            break;
        }
    }
function fnClick(){
    var o=element;
    if(o.type=="checkbox"){
        if(o.disabled)return;
        if(o.checked){
            checkBoxImg.src=preb["checkbox_false"].src;
            }
        else{
            checkBoxImg.src=preb["checkbox_true"].src;
            }

        o.checked=!o.checked;
        }
    }
function Baction(action){
    var o=element;
    if(o.type=="checkbox"){
        if(o.disabled)return;
        if(action=="up"||action=="over"){
            if(o.indeterminate){
                checkBoxImg.src=preb["checkbox_indeter_over"].src;
                }
            else if(o.checked){
                checkBoxImg.src=preb["checkbox_true_over"].src;
                }
            else{
                checkBoxImg.src=preb["checkbox_false_over"].src;
                }
            }
        if(action=="out"){
            if(o.indeterminate){
                checkBoxImg.src=preb["checkbox_indeter"].src;
                }
            else if(o.checked){
                checkBoxImg.src=preb["checkbox_true"].src;
                }
            else{
                checkBoxImg.src=preb["checkbox_false"].src;
                }

            }
        if(action=="down"){
            if(o.indeterminate){
                checkBoxImg.src=preb["checkbox_indeter_down"].src;
                }
            else if(o.checked){
                checkBoxImg.src=preb["checkbox_true_down"].src;
                }
            else{
                checkBoxImg.src=preb["checkbox_false_down"].src;
                }
            o.indeterminate=false;
            }
        }
    }
</script>
</public:component>

測試例子:
復制代碼 代碼如下:

<html>
<head>
<title> 新文檔 </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="FlashSoft">
<meta name="Keywords" content="">
<meta name="Description" content="FlashSoft">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="Text/Css">

input.checkbox{
    behavior:url("behaviors/checkbox.htc");cursor: hand;
    }

</style>
</head>
<body>
<input name="chk1" type="checkbox" class="checkbox" htc_myLabel="音樂" checked>
<input name="chk1" type="checkbox" class="checkbox" htc_myLabel="體育" disabled>
<input name="chk1" type="checkbox" class="checkbox" htc_myLabel="新聞">
<input name="chk1" type="checkbox" class="checkbox" htc_myLabel="不確定屬性1" indeter="true" checked>
<input name="chk1" type="checkbox" class="checkbox" htc_myLabel="不確定屬性2" indeter="true" disabled>
<input name="chk1" type="checkbox" class="checkbox" htc_myLabel="不確定屬性3" indeter="true">
</body>
</html>

下載文件 下載此文件
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 喀喇沁旗| 遵化市| 黔江区| 金塔县| 深泽县| 呼伦贝尔市| 页游| 临城县| 黄梅县| 塘沽区| 长沙县| 镇巴县| 辽阳市| 颍上县| 达孜县| 延吉市| 禹州市| 开原市| 子洲县| 信宜市| 安乡县| 麻阳| 神农架林区| 镇赉县| 连云港市| 吐鲁番市| 肥东县| 雅安市| 华蓥市| 丹凤县| 澄江县| 米脂县| 安福县| 漳州市| 修武县| 云林县| 扎鲁特旗| 闻喜县| 太仓市| 麻城市| 台江县|