我的问题只发生在jquery 1.10.1中。如果我使用jquery 1.8.3,它工作正常。 我有一个列表是'是'并且没有'单选按钮,1'全选'收音机和1'选择无'无线电。我制作了一个代码,以便列表选择所有'是'单击“全部选择”时的单选按钮。收音机,同样适用于“无人”和#39;无线电。问题是,这对每个单选按钮只能工作一次。我的意思是,当我选择所有的' s radio,它可以工作,然后我选择' slelect none'收音机,它工作,然后我回到“选择所有'无线电,它不工作.code在这里:
$(document).ready(function(){
$('.showme-btn').hover(function(){
$(this).next('.showme').fadeToggle(200);
//$(this).parent('.show-outer').toggleClass("show-outer-color");
});
$("input.allradioselect").click(function(){
if($(this).is(':checked')){
$("ul[class*='eachfield'] input.yesradio").attr("checked","true");
}
});
$("input.noradioselect").click(function(){
if($(this).attr('checked', true)){
//alert('ff');
$("ul[class*='eachfield'] input.noradio").attr("checked", "false");
}
});
});
html:
<ul class="cb commongap" style="background-color: #fff; float: left; width: 99%;">
<li style="margin-left: 8px; width: 75%; float: right; text-align: right;"><img src="img/pointer.png" alt="pointer"/> Mark all questions as : Yes <input type="radio" class="allradioselect" name="slelectallorno"/> or No <input type="radio" class="noradioselect" name="slelectallorno"/> </li>
</ul>
<ul class="eachfield-title titlegap">
<li class="eachfield-title-numbering">A.</li>
<li class="ques">Have you received any medical treatment during the last five years or are you awaiting medical or surgical consultation, hospitalization, test or investigation?<span class="showme-btn">?</span>
<div class="showme"> (You need not disclose matters relating to uncomplicated pregnancy, common colds, influenza, hay-fever or any minor ailment requiring a single consultation).(You need not disclose matters relating to uncomplicated pregnancy, common colds, influenza, hay-fever or any minor ailment requiring a single consultation).
</div>
<div class="cb"></div>
</li>
<li class="yes-no"><input type="radio" class="yesradio" name="selecta"/> </li>
<li class="yes-no"><input type="radio" class="noradio" name="selecta"/> </li>
</ul>
<ul class="eachfield-title titlegap">
<li class="eachfield-title-numbering">B.</li>
<li class="ques"> Have you ever had any medical or surgical treatment, including investigations, tests, scans or X-Ray for any of the following illnesses or medical conditions: <span class="showme-btn">?</span>
<div class="showme"> (You need not disclose matters relating to uncomplicated pregnancy, common colds, influenza, hay-fever or any minor ailment requiring a single consultation).(You need not disclose matters relating to uncomplicated pregnancy, common colds, influenza, hay-fever or any minor ailment requiring a single consultation).
</div>
<div class="cb"></div>
</li>
<li class="yes-no"><input type="radio" class="yesradio" name="selectb"/> </li>
<li class="yes-no"><input type="radio"class="noradio" name="selectb"/> </li>
</ul>
小提琴在这里:http://jsfiddle.net/nvk6Y/ 您可以在这个小提琴中将jquery版本更改为1.8.3并查看其中的差异。 提前谢谢。
答案 0 :(得分:0)
尝试:
$(document).ready(function () {
$('.showme-btn').hover(function () {
$(this).next('.showme').fadeToggle(200);
//$(this).parent('.show-outer').toggleClass("show-outer-color");
});
$("input[name='slelectallorno']").click(function () {
if ($(this).val() == 'all') {
$("ul[class*='eachfield'] input.yesradio").prop("checked", true);
} else {
$("ul[class*='eachfield'] input.noradio").prop("checked", true);
}
});
});
<强> jsFiddle example 强>