首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SelectOneRadio和禁用inputText

SelectOneRadio和禁用inputText
EN

Stack Overflow用户
提问于 2012-05-04 11:30:43
回答 2查看 6K关注 0票数 0

这是我的html代码。

代码语言:javascript
复制
        <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。

例如:

  • İf i单击“无线电1”,然后将禁用输入文本1。
  • İf i单击“无线电2”,然后将禁用输入文本2。
  • İf i单击“广播3”,然后将禁用输入文本3。

我该怎么做?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-05-04 13:35:19

将单选按钮值绑定到托管bean属性,并使用<f:ajax>发送ajax请求,并在单选按钮更改时更新视图的部分内容,并根据选定的单选按钮项值使用disabled属性禁用<h:inputText>

例如。

代码语言:javascript
复制
<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>

使用

代码语言:javascript
复制
@ManagedBean
@ViewScoped
public class Bean {

    private String radio;
    private String input1;
    private String input2;
    private String input3;

    // ...
}
票数 1
EN

Stack Overflow用户

发布于 2012-05-04 12:13:37

看看这个,我想这就是你要找的

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10447974

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档