取消选中单选列表按钮和检查选中单选列表按钮


Unchecking Radio List Button And Checking Selected Radio List Button -- Jquery

我在下面包含了两个代码源。

我遇到的问题是,如果您单击其中一个单选按钮(radio-group是按钮组的ID),以前的"选中"选项不会取消选择,新的"选中"选项不会被选中。相反,选择器的click事件发生了,而'checked'选项保持不变。

如何解决这个问题?我曾尝试清除'checked'选项每当一个新的选项是'checked',然后通过Javascript检查该选项,但我没有任何成功。

想法吗?

谢谢!

Javascript代码:
$(function() {
$("#paid-content-box").hide();
$("#general-settings").show();
$("#individual-box-prices").hide();
$("#paypal-preference").hide();
$("#general-settings-link a").click(function() {
    $("#paid-content-box").hide();
    $("#general-settings").show();
    return false;
});
$("#paid-content-settings-link a").click(function() {
    $("#paid-content-box").show();
    $("#general-settings").hide();
    return false;
});
$("input#somepaid").click(function() {  
    document.forms['paidContentForm'].elements['perbox'].disabled = true;
    $("#individual-box-prices").show();
    $("#paypal-preference").show();
    return false;
});
$("input#allfree").click(function() {
    document.forms['paidContentForm'].elements['perbox'].disabled = true;
    $("#individual-box-prices").hide();
    $("#paypal-preference").hide();
    return false;
}); 
$("input#subscription").click(function() {  
    document.forms['paidContentForm'].elements['perbox'].disabled = false;
    $("#individual-box-prices").hide();
    $("#paypal-preference").show();
    return false;
}); 

});

HTML/PHP代码:

<div id="paid-content-box" align="left">
<form name="paidContentForm" action="" method="post">
<h2>Set Your group / Box Prices</h2>
<div id="radio-group" class="radiogroup">
<input id="allfree" type="radio" name="boxprices" value="allfree" checked><label for="allfree">All boxes are free.</label><br />
<input id="subscription" type="radio" name="boxprices" value="subscription"><label for="subscription">Subscription pricing (all paid).</label>
<label for="perbox">Enter price per box: $</label><input id="perbox" type="text" name="subscriptionpriceper" disabled="true"><br />
<input id="somepaid" type="radio" name="boxprices" value="somepaid"><label for="somepaid">Some of the boxes are free and some our paid content.  (Please set the price for each box in the textboxes that will appear below.)</label>
</div>
<div id="individual-box-prices">
<h3>Set Individual Box Prices</h3>
<table id="pricetable">
<tr>
<th>Box Name</th>
<th>Free/Paid</th>
<th>Price</th>
</tr>
<? foreach($boxInfo as $newBox){ ?>
    <tr>
    <td><? echo $newBox['name']?></td>
    <td><span id="box_<? echo $newBox['id']?>_free">Free</span> | <span id="box_<? echo $newBox['id']?>_paid"><a href="javascript:freePaidOption(<? echo $newBox['id']?>, 'paid')">Paid</a></span></td>
    <td><label for="box_<? echo $newBox['id']?>_price">$</label><input id="box_<? echo $newBox['id']?>_price" type="text" name="box_<? echo $newBox['id']?>_price" value="" disabled="true"></td>
    </tr>
    <input type="hidden" name="defaultFreePaid_<? echo $newBox['id']?>" value=""/>
<? } ?>
</table>
</div>
<div id="paypal-preference">
<h3>Payment Preferences</h3>
<label for="paypalemail">Enter your PayPal account email address:</label><input type="text" id="paypalemail" name="paypalemail">
</div>
<br /><br />
<input type="submit" name="SavePaidContent" value="Save" class="inputText">
</form>
</div>

所有的事件处理程序返回false。这可以防止默认操作,即更改所选的单选按钮。