Accept: text / html, application / xhtml + xml, application / xml; q = 0.9, / ; q = 0.8
blockquote>должна быть проблема. JSON используется как
application/json
. Если вы соответствующим образом установите заголовок Accept, вы должны получить правильный ответ. (Есть плагины браузера, которые позволяют устанавливать заголовки, мне нравится «Плакат» для Firefox лучше всего)
Если ваши кнопки сгруппированы по атрибуту имени, попробуйте:
$("input:radio[name=groupName][disabled=false]:first").attr('checked', true);
Если они сгруппированы по родительскому контейнеру, то:
$("#parentId input:radio[disabled=false]:first").attr('checked', true);
$("input:radio[name=groupX]:not(:disabled):first")
Это должно дать вам первый не отключенный переключатель из группы ...
<input type="radio" name="r1"><br>
<input type="radio" name="r1"><br>
<hr>
<input type="radio" name="r2"><br>
<input type="radio" name="r2"><br>
<input type="radio" name="r2"><br>
<script>
$(function(){
//removed duplicates form the following array
$(jQuery.unique(
//create an array with the names of the groups
$('INPUT:radio')
.map(function(i,e){
return $(e).attr('name') }
).get()
))
//interate the array (array with unique names of groups)
.each(function(i,e){
//make the first radio-button of each group checked
$('INPUT:radio[name="'+e+'"]:visible:first')
.attr('checked','checked');
});
});
</script>
jsfiddle = http://jsfiddle.net/v4auT/
Ниже делает то, что вы хотите:
$(document).ready(
function(){
$('input:radio:first-child').attr('checked',true);
}
);
Демонстрация по адресу: JS Bin .
Я проверил первый ответ, и он не разрешил его. Мне пришлось использовать следующее предложение:
jQuery("input:radio[name=groupName]:visible")[0].checked=true;
Эта проверка первой видимой переключателя с именем = groupName
Попробуйте это:
$("input:radio:not(:disabled)").attr("checked", true);
Чтобы проверить первую радио-кнопку только в группе, вы можете
$("parentelement input:radio:not(:disabled):first-child").attr("checked", true);