html - 如何隐藏h :selectBooleanCheckbox

标签 html css jsf

我正在使用自定义复选框的想法

Ryan Fait's Idea

您可以在其中使用自定义图像来创建自定义复选框。但我无法让复选框消失,只有常规框。示例图片在这里
Notice that the checkboxes are still there...

这是我的代码..

  <div id="scheduleContainer">
      <table>
       <tr>
        <!--table header-->
       </tr>
       <tr>
        <td>                                            
<h:selectBooleanCheckbox value="#{schedules[scheduleName][0]}" /><label> 12:00AM</label>
</td>

    </div>

在 CSS 中

#scheduleContainer .checkbox {
    width: 25px;
    height: 20px;
    padding: 0px;
    background: url(../img/schedule-check.gif) no-repeat;
    display: none;
    margin: 0px;
    border: 1px solid black;
    clear: left;
    float: left;
}

还给出了 js 文件。我使用正确吗?

/*
CUSTOM CHECK BOXES - Derived from script by Ryan Fait at
http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/ 
*/

var checkboxHeight = "20";

/* No need to change anything after this */


document.write('<style type="text/css">.styledGroup input { display: none; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>');

var Custom = {
    init: function() {
        var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
        for(a = 0; a < inputs.length; a++) {
            if(inputs[a].type == "checkbox") {
                span[a] = document.createElement("span");
                span[a].className = inputs[a].type;

                if(inputs[a].checked == true) {
                    position = "0 -" + (checkboxHeight*2) + "px";
                    span[a].style.backgroundPosition = position;
                }
                inputs[a].parentNode.insertBefore(span[a], inputs[a]);
                inputs[a].onchange = Custom.clear;
                if(!inputs[a].getAttribute("disabled")) {
                    span[a].onmousedown = Custom.pushed;
                    span[a].onmouseup = Custom.check;
                } else {
                    span[a].className = span[a].className += " disabled";
                }
            }
        }
        document.onmouseup = Custom.clear;
    },
    pushed: function() {
        element = this.nextSibling;
        if(element.checked == true && element.type == "checkbox") {
            this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
        } else if(element.checked != true && element.type == "checkbox") {
            this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
        }
    },
    check: function() {
        element = this.nextSibling;
        if(element.checked == true && element.type == "checkbox") {
            this.style.backgroundPosition = "0 0";
            element.checked = false;
        } else {
            if(element.type == "checkbox") {
                this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
            } 
            element.checked = true;
        }
    },
    clear: function() {
        inputs = document.getElementsByTagName("input");
        for(var b = 0; b < inputs.length; b++) {
            if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
                inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
            } else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
                inputs[b].previousSibling.style.backgroundPosition = "0 0";
            }
        }
    }
}
window.onload = Custom.init;

最佳答案

只需应用 CSS display: none;<h:selectBooleanCheckbox> 生成的 HTML 上.

例如

<h:selectBooleanCheckbox style="display: none;" />

<h:selectBooleanCheckbox styleClass="hide" />

.hide { 
    display: none; 
}

关于html - 如何隐藏h :selectBooleanCheckbox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7650771/

相关文章:

javascript - 单击时不清除 Div?

html - 如何仅垂直固定元素?

java - hibernate - "org.hibernate.LazyInitializationException: could not initialize proxy - no Session"

javascript - 图片的高度与手机/平板电脑的高度相同 - 只能在 Chrome 中正常工作

python - 如何从 Selenium 中的多个类的多个元素中获取数据?

css - IE9 - 从 div 中心放大和缩小的 Animate()

javascript - 如何在按键上做多个动画

ajax - <a4j :commandLink> Not Rerendering

JSF 2 - ResponseWriter.flush() 的意义

javascript - 如何将 JSON 数据格式化为两个 html 表