【问题标题】:HTML JSF inputText disable with checkboxHTML JSF inputText 用复选框禁用
【发布时间】:2014-05-30 14:38:37
【问题描述】:
<table class="layout-table"> 
<tr>
        <td><strong>a. Copy of Contract</strong>
            <br/>
            <p:inputText value="#{question4dDte}"></p:inputText>

             <input type="checkbox" name="chk" id="chk1" value="#{question4dNA}"/> (something like this)
            <br/>
            <h:outputText id="counter24" />
        </td>
    </tr>
   </table>

所以我的这段代码没有按我想要的方式工作,但我不知道该怎么做。我希望能够拥有这样的 inputText 和复选框。

______________   ()

我使用单选按钮是因为它是一个圆圈,但我宁愿使用一个复选框,(如果可以将它做成一个圆圈,那也很棒:))。但我想要做的是,当单击复选框时,它会禁用文本字段。取消选中时,它会启用文本字段。 But when the checkbox is selected it needs to put question4dNA to 2. This is where it makes it a bit harder :(.

【问题讨论】:

  • 在 inputText 中添加 disabled 属性,在复选框中添加 ajax render。

标签: html jsf xhtml


【解决方案1】:

这样做:

  <p:selectOneRadio id="radio" value="#{TheBean.theProperty}">
      <f:selectItem itemLabel="No p:inputText ;)" itemValue="NO" />
      <f:selectItem itemLabel="YES" itemValue="YEP" />
      <p:ajax update="txtHI" />
  </p:selectOneRadio>

  <p:inputText id="txtHI" disabled="#{TheBean.theProperty == 'NO'}" />

豆豆:

private String theProperty;
// set & get

我正在使用 PrimeFaces,但几乎相同。尝试使用 f:ajax。

【讨论】:

    【解决方案2】:

    您可以在http://prpdemo.com/disable-field.php 看到一个工作示例。但这里是做你需要的代码。

        <form name="form1" id="form1" action="#" method="post">
        <label for ="question4dDte">question4dDte
        <input type="question4dDte" name="question4dDte" id="question4dDte" /></label>
        <input type="checkbox" name="cb1" id="cb1" onclick="disableField('question4dDte');">
        </form>
        <script type="text/JavaScript">
        <!--
        function disableField(fieldID)
          {
          // By passing a variable for the fieldID,
             you can use the same script for multiple fields and just pass the fieldID in the call.
          if($('#'+fieldID).is (':disabled'))
          {
            $('#'+fieldID).prop('disabled', false);
          }else{
            $('#'+fieldID).prop('disabled','disabled');
          }
          alert("The text box is disabled. "+$('#'+fieldID).is (':disabled'));
          // The previous line can be removed or commented out. It is just for confirmation that the form is working.
         }
        //-->
        </script>
    

    【讨论】:

      猜你喜欢
      • 2015-02-25
      • 1970-01-01
      • 2011-04-03
      • 2015-06-20
      • 2012-08-12
      • 1970-01-01
      • 2014-07-29
      • 1970-01-01
      • 2019-06-08
      相关资源
      最近更新 更多