在单选按钮上显示一些组件单击JSF

时间:2017-12-15 08:48:47

标签: javascript jsf

                    注册为::

<td>        <h:selectOneRadio id="selection" value="#{LoginBean.role}" label="Action" required="true" onclick="javascript:showUserSelection(this)">
                            <f:selectItem itemValue="Customer" itemLabel="Customer" />
                            <f:selectItem itemValue="Manager" itemLabel="Manager" />
                            <p:ajax process="console" update="@form" />
                        </h:selectOneRadio>
            </td>
          </tr>

          <tr>
            <th><h:outputLabel value="Enter your Fee ::" id="fee"></h:outputLabel></th>

在上面的代码中,我只想在选中Manager单选按钮时显示outputLabel。我写了javascript,但它没有用。

<script>
   function showUserSelection(idFrom) {  
     if (document.getElementById){  
     var valueFrom = idFrom.value;  
       if (valueFrom == 'Manager'){  
         document.getElementById('fee').className="visible";
       }  
       else{  

         document.getElementById('fee').className="invisible"  
       }  
     }  
   } 
   </script>

? 有人可以告诉我上面有什么问题吗?

1 个答案:

答案 0 :(得分:-1)

纯粹的javascript方法

window.onload = showHideMsg();

function showHideMsg() {
   document.getElementById("rdButton").onclick = () => {
      document.getElementById("msg").classList -= 'hide';
   }
}
.hide {
  display : none;
}
<input type="radio" id="rdButton"/>
A message will appear if u click the radio button
<div id="msg" class="hide">
You clicked radio...
</div>