Text box appear on radio button check

蹲街弑〆低调 提交于 2019-12-20 04:15:08

问题


I have the following..

<table id='table_columns'>
    <td align="center">
        <input type="radio" name="WIDTH" value="1" <?php echo ($config->get('WIDTH','COLUMNS') == "1")?'CHECKED':'';?> />
        <p>4 Columns</p>
    </td>
    <td align="center">
        <input type="radio" name="WIDTH" value="2" <?php echo ($config->get('WIDTH','COLUMNS') == "2")?'CHECKED':'';?> />
        <p>3 Columns</p>
    </td>
    <td align="center">
        <input type="radio" name="WIDTH" value="3" <?php echo ($config->get('WIDTH','COLUMNS') == "3")?'CHECKED':'';?> />
        <p>Custom</p>
    </td>
    <tr>
        <td align="right">
            <p>Column 1</p>
        </td>
        <td align="left">
            <input class="txt" size="3" maxlength="3"  name="WIDTH1" Title="Insert the desired width" value="<?php echo $config->get('WIDTH1','COLUMNS')?>" />
        </td>
    </tr>

When the Custom radio button is checked I would like the text box below to appear. If any of the other radio buttons are checked I don't want it to show. How would I do this?

Thanks


回答1:


If the radio buttons map to the next rows cell you can try this:

<script type="text/javascript">
    $(function(){
        $("table input:radio").click(function(){
            var $radio = $(this);
            var index = $radio.closest("td").index();
            $radio.closest("tr").next().find("input:text").eq(index)
                .toggle($radio.is(":checked"));
        });
    });
</script>

or if there is only 1 textbox in the next row you can try:

<script type="text/javascript">
    $(function(){
        $("table input:radio").click(function(){
            var $radio = $(this);
            $radio.closest("tr").next().find("input:text")
                .toggle($radio.is(":checked"));
        });
    });
</script>

Your markup looks invalid or you just copied/pasted it wrong



来源:https://stackoverflow.com/questions/7176980/text-box-appear-on-radio-button-check

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!