[英]HTML JSF inputText disable with checkbox
<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和一个这样的复选框。
______________ ()
我之所以使用单选按钮,是因为它是一个圆圈,但是我宁愿使用一个复选框,(如果可能的话也可以使它成为一个很棒的圆圈:))。 但是我想做的是,当单击复选框时,它将禁用文本字段。 取消选中它会启用文本字段。 但是,当选中此复选框时,需要将question4dNA设置为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>
做这个:
<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。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.