gpt4 book ai didi

javascript - 单击单选按钮时启用输入框

转载 作者:行者123 更新时间:2023-12-01 02:23:53 25 4
gpt4 key购买 nike

我有以下 PHP GridView 代码

<table>
<tr>
<td>
<input type="radio" name="planId" id="planId1" value="1">
<label for="planId1">Plan 1</label>
</td>
<td>$5 <label>per month</label></td>
<td class="input-field col m6 subForm"><input type="number" name="monthTxt" id="monthTxt" class="planId1" min="1" maxlength="2" value="1" disabled></td>
</tr>
<tr>
<td>
<input type="radio" name="planId" id="planId2" value="1">
<label for="planId1">Plan 2</label>
</td>
<td>$5 <label>per month</label></td>
<td class="input-field col m6 subForm"><input type="number" name="monthTxt" id="monthTxt" class="planId2" min="1" maxlength="2" value="1" disabled></td>
</tr>
<tr>
<td>
<input type="radio" name="planId" id="planId3" value="1">
<label for="planId1">Plan 3</label>
</td>
<td>$5 <label>per month</label></td>
<td class="input-field col m6 subForm"><input type="number" name="monthTxt" id="monthTxt" class="planId1" min="1" maxlength="2" value="1" disabled></td>
</tr>
</table>

根据数据库数据,上面的'tr'可以是多个。我的要求是,每当我单击单选按钮时,禁用的输入文本字段应该为 false。

请告诉我如何实现这一点,行数最多可达 10 行。下面是我编写的脚本

$('input:radio').change(function() {
if($(this).is(":checked"))
$(this).parent().find("input:text").attr("disabled",false);
});

最佳答案

  1. 使用closest('tr')
  2. 使用find()时使用输入的类
  3. 要选择号码类型,请使用“input[type=number]”

$('input:radio').change(function() {

if ($(this).is(":checked"))
$(this).closest('table').find("input[type=number]").not(this).attr("disabled", true);
$(this).closest('tr').find("input[type=number]").attr("disabled", false);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<table>
<tr>
<td>
<input type="radio" name="planId" id="planId1" value="1">
<label for="planId1">Plan 1</label>
</td>
<td>$5 <label>per month</label></td>
<td class="input-field col m6 subForm"><input type="number" name="monthTxt" id="monthTxt" class="planId1" min="1" maxlength="2" value="1" disabled></td>
</tr>
<tr>
<td>
<input type="radio" name="planId" id="planId2" value="1">
<label for="planId1">Plan 2</label>
</td>
<td>$5 <label>per month</label></td>
<td class="input-field col m6 subForm"><input type="number" name="monthTxt" id="monthTxt" class="planId2" min="1" maxlength="2" value="1" disabled></td>
</tr>
<tr>
<td>
<input type="radio" name="planId" id="planId3" value="1">
<label for="planId1">Plan 3</label>
</td>
<td>$5 <label>per month</label></td>
<td class="input-field col m6 subForm"><input type="number" name="monthTxt" id="monthTxt" class="planId1" min="1" maxlength="2" value="1" disabled></td>
</tr>
</table>

关于javascript - 单击单选按钮时启用输入框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48972096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com