【问题标题】:Show some component on radio button click JSF [duplicate]在单选按钮上显示一些组件单击 JSF [重复]
【发布时间】:2017-12-15 08:48:47
【问题描述】:

注册为 ::

<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>

在上面的代码中,我只想在选择管理器单选按钮时显示 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>

? 有人可以建议我上面有什么问题吗?

【问题讨论】:

  • 调试,调试,调试。所有客户端的东西......

标签: javascript jsf


【解决方案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>

【讨论】:

  • 您好,感谢您的建议。但是,我需要为 JSF 做,而在 JSF 中它不起作用。
  • @stephen:但是您自己创建的解决方案也是纯 javascript...您的 jsf xhtml 客户端是纯 html 和 javascript。您要么必须查看此答案并将其“移植”到您的 ID 等,要么采取完全不同的方法
猜你喜欢
  • 2018-05-04
  • 1970-01-01
  • 2019-05-17
  • 2018-01-06
  • 2015-01-07
  • 2011-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多