Javascript 使用jquery控制表单字段和表单赢得';不要屈服
我使用一个简单的脚本来启用和禁用基于单选按钮选择的表单字段。我已经使用这个脚本多次,它的工作完美无瑕。当我选择第一个单选按钮并单击submit按钮完成表单时,什么也没有发生。当我完成表格时,选择第二个单选按钮并单击它提交的提交按钮。守则的有关部分如下:Javascript 使用jquery控制表单字段和表单赢得';不要屈服,javascript,jquery,forms,Javascript,Jquery,Forms,我使用一个简单的脚本来启用和禁用基于单选按钮选择的表单字段。我已经使用这个脚本多次,它的工作完美无瑕。当我选择第一个单选按钮并单击submit按钮完成表单时,什么也没有发生。当我完成表格时,选择第二个单选按钮并单击它提交的提交按钮。守则的有关部分如下: <li><input type="radio" name="pymt_details" id="pymt_details_1" value="pymt_det
<li><input type="radio" name="pymt_details" id="pymt_details_1" value="pymt_details_1" required>
Amount billed on <input type="text" name="pymt_details_1_a" id="pymt_details_1_a" style="width:
80px" disabled> and amount billed on the <input type="text" name="pymt_details_1_b" id="pymt_details_1_b"
style="width: 80px" disabled> day of each month</li>
<li><input type="radio" name="pymt_details" id="pymt_details_2" value="pymt_details_2"> <input
type="text" name="pymt_details_2_a" id="pymt_details_2_a" style="width: 150px" disabled> on the <input
type="text" name="pymt_details_2_b" id="pymt_details_2_b" style="width: 80px" disabled> and <input type="text"
name="pymt_details_2_c" id="pymt_details_2_c" style="width: 150px" disabled> on the <input type="text"
name="pymt_details_2_d" id="pymt_details_2_d" style="width: 80px" disabled> day of each month</li>
<input name="print" id="print" type="submit" value="Generate printable form" />
为了解决这个问题,我已经注释掉了这段代码的一部分,但无论怎样,我都无法使用第一个选择来运行它
感谢您的帮助!谢谢。旁注:每当您发现自己在编写重复的、几乎完全相同的代码时,请假设有更好的方法。你可以通过一个简单的数组/循环来大量减少JS。问题不是你在问题中添加了什么-你能在jQuery代码中添加表单提交部分吗?请检查并回答你的问题,包括我们需要的代码,以便我们能够看到问题所在,并能够提供帮助!请在JSFIDLE上添加代码。所以其他人可以看到整个问题。thanks@Mitya我看到了这一点,并试图找到如何在循环中实现这一点的答案,但没有找到任何答案,尽管我承认这是我参与的一个更大的项目的第二步,也是使用JavaScript的新手。你能给我指一个资源吗?我希望能做得更好。
$("#pymt_details_1").click(function() {
$("#pymt_details_1_a").prop("disabled",false);
$("#pymt_details_1_b").prop("disabled",false);
$("#pymt_details_2_a").prop("disabled",true);
$("#pymt_details_2_b").prop("disabled",true);
$("#pymt_details_2_c").prop("disabled",true);
$("#pymt_details_2_d").prop("disabled",true);
$("#pymt_details_1_a").focus();
});
$("#pymt_details_2").click(function() {
$("#pymt_details_1_a").prop("disabled",true);
$("#pymt_details_1_b").prop("disabled",true);
$("#pymt_details_2_a").prop("disabled",false);
$("#pymt_details_2_b").prop("disabled",false);
$("#pymt_details_2_c").prop("disabled",false);
$("#pymt_details_2_d").prop("disabled",false);
$("#pymt_details_2_a").focus();
});