单选框 和 下拉框 readonly 属性

 单选框 和  下拉框 没有readonly 属性,通过其他方法可以实现类似效果:

function setCheckBoxReadOnly(obj, checkStatus) {//checkStatus:true 是readonly效果
 obj.onclick = function(){return !checkStatus;};
}

 

function setSelectReadOnly(obj){
    if(obj){
        obj.onbeforeactivate = function(){return false;};
        obj.onfocus = function(){obj.blur();};
        obj.onmouseover = function(){obj.setCapture();};
        obj.onmouseout = function(){obj.releaseCapture();};
        obj.style.background = "#CCCCCC";
    }
}

 

function setSelectReadOnlyFalse(obj){
    if(obj){
        obj.onbeforeactivate ='';
        obj.onfocus ='';
        obj.onmouseover ='';
        obj.onmouseout ='';
        obj.style.background = "#FFFFFF";
    }
}

你可能感兴趣的:(javascript)