我试图禁用这些单选按钮,当一个loadActive链接被点击,但由于某种原因,它只禁用顺序中的第一个,然后跳过其余。
- <form id="chatTickets" method="post" action="/admin/index.cfm/">
- <input id="ticketID1" type="radio" checked="checked" value="myvalue1" name="ticketID"/>
- <input id="ticketID2" type="radio" checked="checked" value="myvalue2" name="ticketID"/>
- </form>
- <a href="#" title="Load ActiveChat" id="loadActive">Load Active</a>
这里是我使用的jquery:
- jQuery("#loadActive").click(function() {
- //I have other code in here that runs before this function call
- writeData();
- });
- function writeData() {
- jQuery("input[name='ticketID']").each(function(i) {
- jQuery(this).attr('disabled','disabled');
- });
- }
解决方法
我重构你的代码,有点,这应该工作:
- jQuery("#loadActive").click(writeData);
- function writeData() {
- jQuery("#chatTickets input:radio").attr('disabled',true);
- }
如果表单上有两个以上的单选按钮,则必须修改选择器,例如,您可以使用starts with attribute filter选择ID以ticketID开头的无线电:
- function writeData() {
- jQuery("#chatTickets input[id^=ticketID]:radio").attr('disabled',true);
- }