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"> No</td>
<td>
<input type="radio" style="padding-left: 20px;" value="1" name="yesnopricing"> 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中执行此操作:您好,谢谢您的评论。如何将代码片段添加到页面中?不客气,请检查。