0
$('#tableId').on('change', ':radio', function () {
    console.log($(this));
    console.log($(this).attr('checked'));
});

第二个控制台语句打印未定义。我不知道为什么,这个 $(this) 看起来它持有正确的输入元素。

编辑:

我正在尝试做这样的事情http://jsfiddle.net/briguy37/EtNXP/但我的单选按钮在表格中

$('#tableId').on('change', ':radio', function () {
    console.log($(this).is(':checked'));
    var prevValue = $(this).attr('previousValue');
    if(prevValue == "true")
    {
      $(this).attr('checked', false);
    }
    $(this).attr('previousValue', $(this).is(':checked'));
  });
4

2 回答 2

1

尝试使用this.checkedor$(this).prop('checked')$(this).is(':checked')代替使用attr.

$('#tableId').on('change', ':radio', function () {
    console.log($(this));
    console.log(this.checked);
});

你想这样做,使收音机不可选择:

 $('#radioinstant').click(function() {
    var previousValue = $(this).data('previousValue');
    this.checked = !previousValue;
    $(this).data('previousValue', this.checked);
});

演示

也不要在change事件上执行此操作(它发生在更改完成之后,您不能再从更改事件内部更改无线电的状态),您需要在更改之前发生的click事件以及您可以取消或更改的位置执行此操作单选按钮的状态。

改变:

$('#tableId').on('change', ':radio', function () {

至:

$('#tableId').on('click', ':radio', function () {
于 2013-07-02T20:19:07.110 回答
0

试试这个并相应地更改选择器。

$('#tableId').on('click', ':radio', function() {
   if($(this).is(':checked'))
       console.log("Yes");
   else
       console.log("No");
});
于 2013-07-02T20:18:51.497 回答