我的页面中有以下单选按钮
<input type="radio" name="launch_selection" class="linkToSectionSurvey expandSectionSurvey" id="linkTosectionSurvey1" rel="Surveysection1">
<input type="radio" name="launch_selection" id="all_active_members" class="linkToSectionSurvey expandSectionSurvey">
这是我用于单选按钮单击事件的js文件中的代码。
jQuery('input[type=radio].expandSectionSurvey').live('click',function(e){
});
我的要求是检查单击的类。
单击单选按钮将调用jQuery函数。
唯一的问题是,即使单击它,它也不会显示“已选中”。
它是使用jquery 1.4.2版的旧应用程序,由于几乎在所有地方都使用了“ .live”,所以我无法升级它。
提前致谢。
正如此评论所说的::
.live()
jQuery中已弃用,在中已1.7
删除1.9
。请转换成.on()
因此,仅在这种情况下,仅当动态生成/创建单选元素时,才应遵循event delegation
事件绑定。您必须将.on()
事件监听器与change
事件一起转换:
jQuery(document).on('change', 'input[type=radio]', function(e){
if($(this).hasClass('expandSectionSurvey')){
// do something
}else{
// do something else
}
});
根据评论jQuery v1.4.x:
jQuery('input[type=radio]').live('change', function(e){
if($(this).hasClass('expandSectionSurvey')){
// do something
}else{
// do something else
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句