我正在寻找编写jQuery来仅启用单选按钮,具体取决于根据某些业务逻辑选择哪些单选按钮。根据用户选择启用和禁用单选按钮
本质上有3组,每组3个单选按钮,它结了看起来像(我的道歉与这个例子HTML是冗长的,但希望这将说明我的意思):
<p>
<label for="group_one">Group One</label>
</p>
<p>
<div class="group_one">
<div id="group_one_choice_one">
<label for="group_one_choice_one">Choice One</label>
<br />
<input checked="checked" id="choice_one" type="radio" value="1" />
<br />
</div>
<div id="group_one_choice_two">
<label for="group_one_choice_two">Choice Two</label>
<br />
<input id="group_one_choice_two" type="radio" value="2" />
<br />
</div>
<div id="group_one_choice_three">
<label for="group_one_choice_three">Choice Three</label>
<br />
<input id="choice_three" type="radio" value="3"/ >
<br />
</div>
</div>
</p>
<p>
<label for="group_two">Group Two</label>
</p>
<p>
<div class="group_two">
<div id="group_two_choice_one">
<label for="group_two_choice_one">Choice One</label>
<br />
<input checked="checked" id="choice_one" type="radio" value="1" />
<br />
</div>
<div id="group_two_choice_two">
<label for="group_two_choice_two">Choice Two</label>
<br />
<input id="group_two_choice_two" type="radio" value="2" />
<br />
</div>
<div id="group_two_choice_three">
<label for="group_two_choice_three">Choice Three</label>
<br />
<input id="choice_three" type="radio" value="3"/ >
<br />
</div>
</div>
</p>
<p>
<label for="group_three">Group Three</label>
</p>
<p>
<div class="group_three">
<div id="group_three_choice_one">
<label for="group_three_choice_one">Choice One</label>
<br />
<input checked="checked" id="choice_one" type="radio" value="1" />
<br />
</div>
<div id="group_three_choice_two">
<label for="group_three_choice_two">Choice Two</label>
<br />
<input id="group_three_choice_two" type="radio" value="2" />
<br />
</div>
<div id="group_three_choice_three">
<label for="group_three_choice_three">Choice Three</label>
<br />
<input id="choice_three" type="radio" value="3"/ >
<br />
</div>
</div>
</p>
凡变得棘手的是确定要显示哪些单选按钮以及启用哪个单选按钮所需的逻辑。用户必须从每个组中选择一个选项,但不能从一个组到另一个组重复相同的选择。
理想情况下,当用户进入页面时,所有单选按钮都将可用,但未被选中。
如果用户首先在第三组中选择(例如)选择二,那么该脚本应该禁用组1和组2中的选择二。如果用户然后在第二组中选择选择三,那么它应该仅在第一组中启用选择一,等等。
任何帮助将非常,非常感谢。我会张贴我一直试图编写的jQuery来解决这个问题,但我不认为我一直在讨论这个问题,并且会喜欢通过它进行工作的任何帮助。谢谢!
这种方法的问题(?)是,一旦我做出选择,我无法改变主意,因为所有按钮都被禁用。所以至少要添加一个清晰的按钮。 – Zed 2009-08-23 15:32:22
你确定单选按钮是这里的答案,而不是复选框 – 2009-08-23 15:33:42