jquery函数未执行

时间:2013-10-31 06:07:15

标签: jquery

我正在使用这个jQuery函数但是当我运行我的应用程序时,这个函数不会执行。

实际上控制转到了这个函数。但是没有进入它来执行代码。

是什么原因?

这个func.is用于检查无线电广播。

$("input[type='radio']").click(function () {
    var previousValue = $(this).attr('previousValue');
    var name = $(this).attr('name');
    if (previousValue == 'checked') {
        $(this).removeAttr('checked');
        $(this).attr('previousValue', false);
    } else {
        $("input[name=" + name + "]:radio").attr('previousValue', false);
        $(this).attr('previousValue', 'checked');
    }
});

1 个答案:

答案 0 :(得分:0)

使用.prop()代替.attr()

.change()设置了.click()

$("input[type='radio']").change(function () {
    var previousValue = $(this).prop('previousValue');
    var name = $(this).prop('name');
    if (previousValue == 'checked') {
        $(this).removeAttr('checked');
        $(this).prop('previousValue', false);
    } else {
        $("input[name=" + name + "]:radio").prop('previousValue', false);
        $(this).prop('previousValue', 'checked');
    }
});

阅读.prop() vs .attr()

相关问题