2014-01-06 24 views
0

我在更新JQuery页面上的第二个单选按钮值时遇到问题。JQuery第二个单选按钮不起作用

这里是我的HTML:

<div id="system-modes-fpa" class="ui-buttonset"> 
    <input type="radio" id="system-fpa-mode-TIMELAPSE" name="radio" value="TIMELAPSE" class="ui-helper-hidden-accessible"> 
    <label for="system-fpa-mode-TIMELAPSE" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-left" role="button" aria-disabled="false" aria-pressed="false"><span class="ui-button-text">Timelapse</span> 
    </label> 
    <input type="radio" id="system-fpa-mode-CONTINUOUS" name="radio" value="CONTINUOUS" class="ui-helper-hidden-accessible"> 
    <label for="system-fpa-mode-CONTINUOUS" class="ui-button ui-widget ui-state-default ui-button-text-only" role="button" aria-disabled="false" aria-pressed="false"><span class="ui-button-text">Continuous</span> 
    </label> 
    <input type="radio" id="system-fpa-mode-RAMP_AND_HOLD" name="radio" value="RAMP_AND_HOLD" class="ui-helper-hidden-accessible" checked="checked"> 
    <label for="system-fpa-mode-RAMP_AND_HOLD" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-right" role="button" aria-disabled="false" aria-pressed="false"> <span class="ui-button-text">Ramp and Hold</span> 
    </label> 
</div> 
<div id="system-modes-stillimage" class="ui-buttonset"> 
    <input type="radio" id="system-stillimage-mode-TIMELAPSE" name="radio" value="TIMELAPSE" class="ui-helper-hidden-accessible"> 
    <label for="system-stillimage-mode-TIMELAPSE" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-left" role="button" aria-disabled="false" aria-pressed="false"> <span class="ui-button-text">Timelapse</span> 
    </label> 
    <input type="radio" id="system-stillimage-mode-CONTINUOUS" name="radio" value="CONTINUOUS" class="ui-helper-hidden-accessible"> 
    <label for="system-stillimage-mode-CONTINUOUS" class="ui-button ui-widget ui-state-default ui-button-text-only" role="button" aria-disabled="false" aria-pressed="false"><span class="ui-button-text">Continuous</span> 
    </label> 
    <input type="radio" id="system-stillimage-mode-RAMP_AND_HOLD" name="radio" value="RAMP_AND_HOLD" class="ui-helper-hidden-accessible"> 
    <label for="system-stillimage-mode-RAMP_AND_HOLD" class="ui-button ui-widget ui-state-default ui-button-text-only ui-state-active ui-corner-right" role="button" aria-disabled="false" aria-pressed="true"><span class="ui-button-text">Ramp and Hold</span> 
    </label> 
</div> 

这里是我的javascript:

var continuousButton = $('#system-fpa-mode-CONTINUOUS'); 
continuousButton.prop('checked', true); 

// try uncommenting the following two lines to see the first set of radio buttons lose their value 
//var stillimageButton = $('#system-stillimage-mode-CONTINUOUS'); 
//stillimageButton.prop('checked', true); 

http://jsfiddle.net/bYk6y/10/

当第二更新被调用时,第一无线电组将失去它的价值。我究竟做错了什么?

+3

你只有一个单选按钮组。他们都有'name ='radio''。 – Barmar

回答

0

更改name属性:

第一组应该是这样的

name="radio1" 

而第二

name="radio2" 
+0

你发现了错误,所以我给你信用。非常感谢!! –

+0

@mikeboldischar我的荣幸。我们都遇到过这样的小事情。 – Kehlan

0

单选按钮组是所有具有相同name属性按钮。他们是否在不同的DIV中并不重要。如果你想让这两个团体分开,你必须给他们不同的名字。所以第一组可能是:

name="radio-fpa" 

和第二将是:

name="radio-stillimage" 
+0

感谢您的解释。这正是我所做的。 –