HTML JSF inputText禁用复选框


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

所以我有这个代码,这是不工作的方式,我想,但我不知道如何做到这一点。我希望能有这样的输入文本和复选框

______________   ()

我使用单选按钮,因为它是一个圆圈,但我宁愿使用一个复选框代替,(如果它可能使它成为一个圆圈,那也会很棒:))。我想做的是当复选框被点击时它会禁用文本框。当未选中它时,它启用文本字段。但是当选中复选框时,它需要将question4dNA置为2。(.

这样做:

  <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'}" />

TheBean:

private String theProperty;
// set & get

我使用的是PrimeFaces,但几乎是相同的。尝试使用f:ajax.

您可以在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>

最新更新