Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在单选按钮上隐藏和显示文本框_Javascript_Php_Jquery - Fatal编程技术网

Javascript 如何在单选按钮上隐藏和显示文本框

Javascript 如何在单选按钮上隐藏和显示文本框,javascript,php,jquery,Javascript,Php,Jquery,我希望下面代码中的文本框在用户选择“是”时显示,如果选择“否”则隐藏 <table> <tr> <td style="width: 130px"> <label for="edit-title" class="control-label" style="font-size: small;">Willing to Post?</label> </td>

我希望下面代码中的文本框在用户选择“是”时显示,如果选择“否”则隐藏

<table>
    <tr>
        <td style="width: 130px">
            <label for="edit-title" class="control-label" style="font-size: small;">Willing to Post?</label>
        </td>
        <td>
            <input type="radio" value="0" name="yesnopricing" checked="checked">&nbsp;&nbsp;No</td>
        <td>
            <input type="radio" style="padding-left: 20px;" value="1" name="yesnopricing">&nbsp;&nbsp;Yes</td>

        <td style="width: 25px"></td>
        <td>
            <input type="text" name="postageprice" placeholder="Postage Price">
        </td>
    </tr>
</table>

尝试进行一些dom遍历,然后使用值进行切换

$(":radio[name='yesnopricing']").change(function(){
  $(this).parent().nextAll("td:has(input[name='postageprice'])").toggle(!!+this.value);
});

将事件onclick添加到radio类型的两个输入。然后检查选择了哪一个并取决于调用方法hide或show on input type text。

请尝试使用类或id来标识输入,然后使用单击事件显示隐藏字段,检查下面的示例

希望这有帮助

一小条 $'body'。单击,'.yes_pricing',函数{ $‘后期价格’。显示; } $'body'。单击,'.no_pricing',函数{ $‘后期价格’。隐藏; } 愿意发帖吗? 不 对
因此,您已经用PHP、JavaScript和jQuery标记了您的问题,但没有发布任何来自这些语言的代码。您尝试过什么?虽然您有一个基于表的布局,但实际上不适用于此,但是如果您可以重构标记,可以使用:checked选择器在纯CSS中执行此操作:您好,谢谢您的评论。如何将代码片段添加到页面中?不客气,请检查。