1

使用这个 jquery 代码:

$("#targeting input:radio").each(function() {
   console.log ($(this).attr("selected"));
});

HTML:

 <input type="radio" id="dateFromTo" name="muScheduleDateRange" value="2" selected="someval"/>

selected在console.log我得到了someval

4

3 回答 3

7

selected是一个布尔值。您不能将其设置为除undefinedor之外的任何内容"selected"。如果要为 附加一些值input,请使用该value属性。如果要为 附加一些附加值,请input使用数据属性。

于 2013-08-27T16:31:58.753 回答
0

尝试这个

console.log($('#targeting input:radio:checked').val())

jquery val

于 2013-08-27T16:37:37.143 回答
0

尝试这个:

console.log($(this).prop('checked'));

将返回 true 或 false,具体取决于是否选中了单选按钮。

资源

于 2013-08-27T16:39:37.373 回答