这是我的html代码。
<table >
<tr>
<th rowspan="3">
<h:selectOneRadio layout="pageDirection"
onClick="alert('selam')" id="selectOneRadio">
<f:selectItem itemValue="Categori" itemLabel="Radio 1" />
<f:selectItem itemValue="Service" itemLabel="Radio 2" />
<f:selectItem itemValue="Follower" itemLabel="Radio 3" />
</h:selectOneRadio>
</th>
<td>
<h:inputText value="inputText 1" />
</td>
</tr>
<tr>
<td>
<h:inputText value="inputText 2" />
</td>
</tr>
<tr>
<td>
<h:inputText value="inputText 3" />
</td>
</tr>
</table>我想选择一个radioButtons。当我单击其中之一时,我希望禁用inputText。
例如:
我该怎么做?
发布于 2012-05-04 13:35:19
将单选按钮值绑定到托管bean属性,并使用<f:ajax>发送ajax请求,并在单选按钮更改时更新视图的部分内容,并根据选定的单选按钮项值使用disabled属性禁用<h:inputText>。
例如。
<h:panelGroup id="inputs">
<table>
<tr>
<th rowspan="3">
<h:selectOneRadio value="#{bean.radio}" layout="pageDirection">
<f:selectItem itemValue="Categori" itemLabel="Radio 1" />
<f:selectItem itemValue="Service" itemLabel="Radio 2" />
<f:selectItem itemValue="Follower" itemLabel="Radio 3" />
<f:ajax render="inputs" />
</h:selectOneRadio>
</th>
<td>
<h:inputText value="#{bean.input1}" disabled="#{bean.radio == 'Categori'}" />
</td>
</tr>
<tr>
<td>
<h:inputText value="#{bean.input2}" disabled="#{bean.radio == 'Service'}" />
</td>
</tr>
<tr>
<td>
<h:inputText value="#{bean.input3}" disabled="#{bean.radio == 'Follower'}" />
</td>
</tr>
</table>
</h:panelGroup>使用
@ManagedBean
@ViewScoped
public class Bean {
private String radio;
private String input1;
private String input2;
private String input3;
// ...
}发布于 2012-05-04 12:13:37
看看这个,我想这就是你要找的
<html>
<head>
<script type="text/javascript">
function enable_area(opt)
{
//get the required document element and disable corresponding element.
document.form.textarea1.disabled = (opt == 'Categori' ? true : false);
document.form.textarea2.disabled = (opt == 'service' ? true : false);
document.form.textarea3.disabled = (opt == 'Follower' ? true : false);
}
</script>
</head>
<body>
<form action="" method="post" name="form">
<!--Pass the value field as selector when clicked on radio button-->
Radio1 <input type="radio" name="radio" value="Categori" onclick="enable_area(this.value);" />
<textarea name="textarea1"></textarea>
<br />
Radio2 <input type="radio" name="radio" value="service" onclick="enable_area(this.value);" />
<textarea name="textarea2"></textarea>
<br />
Radio3 <input type="radio" name="radio" value="Follower" onclick="enable_area(this.value);" />
<textarea name="textarea3"></textarea>
</form>
</body>
</html>https://stackoverflow.com/questions/10447974
复制相似问题