2013-10-31 117 views
0

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

实际控制去这个func.but不去这里面执行代码。

是什么原因?

这个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'); 
    } 
}); 
+0

什么是你想在这里做什么? –

+0

我想检查取消选中无线电输入。 – user2243331

+0

是的,我得到了,但什么是'previousValue' –

回答

0

使用.prop()而不是.attr()

.change() instated。点击()的

$("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()

+0

n abt .js fil.i包含任何.js文件吗? ????? – user2243331

+0

@ user2243331这是什么意思? –

+1

它唯一依赖的JS文件是jQuery。 – Barmar