<input type="radio" id="checkMain" />
<input type="radio" id="checkMain1" />
<input type="radio" id="checkMain2" />
$(function()
{
$("input[id=checkMain]").click(function() {
var otherCks = $("input[id^=checkMain]").not(this);
if (!$(this).is(":checked")) {
$(".child").attr("disabled", true);
otherCks.removeAttr("disabled");
} else {
$(".child").removeAttr("disabled");
otherCks.attr("disabled", true)
}
});
$("#chk_all").click(function() {
var checked_status = this.checked;
$("input[id^=chk]").each(function() {
this.checked = checked_status;
});
});
});
$(function()
{
$("input[id=checkMain1]").click(function() {
var otherCks = $("input[id^=checkMain]").not(this);
if (!$(this).is(":checked")) {
$(".child,.child1").attr("disabled", true);
otherCks.removeAttr("disabled");
} else {
$(".child,.child1").removeAttr("disabled");
otherCks.attr("disabled", true)
}
});
$("#chk_all").click(function() {
var checked_status = this.checked;
$("input[id^=chk]").each(function() {
this.checked = checked_status;
});
});
});
$(function()
{
$("input[id=checkMain2]").click(function() {
var otherCks = $("input[id^=checkMain]").not(this);
if (!$(this).is(":checked")) {
$(".child,.child1").attr("disabled", true);
otherCks.removeAttr("disabled");
} else {
$(".child,.child1").removeAttr("disabled");
otherCks.attr("disabled", true)
}
});
$("#chk_all").click(function() {
var checked_status = this.checked;
$("input[id^=chk]").each(function() {
this.checked = checked_status;
});
});
});
示例代碼上面的代碼完全適用於複選框,但單選按鈕單選按鈕不會被禁用一旦點擊了<a href="http://jsfiddle.net/harshilshah/sBgZw/23" rel="nofollow">http://jsfiddle.net/harshilshah/sBgZw/23</a></p> <p>
總之,工作應該是這樣的dosent工作:當我點擊radiobutton1時,其他人應該被禁用(不可用)。當我重新點擊radiobutton1時,其他人應該再次可用。
http://jsfiddle.net/harshilshah/sBgZw/23/ – Harshil 2011-02-06 10:20:33
中的示例代碼你能更具體嗎?單擊時,您想要禁用哪個確切的單選按鈕? – AbdullahC 2011-02-06 10:22:59
上面的代碼完美適用於複選框,但單選按鈕 – Harshil 2011-02-06 10:23:17