IE,firefox下jquery获取一组checkbox选中值的问题

 

HTML 代码:
< form >
< input type = " checkbox "  name = " newsletter "   checked = " checked "  value = " Daily "   />
< input type = " checkbox "  name = " newsletter "  value = " Weekly "   />
< input type = " checkbox "  name = " newsletter "   checked = " checked "  value = " Monthly "   />
</ form >
jQuery 代码:
$(
" input:checked " )
结果:
< input type = " checkbox "  name = " newsletter "   checked = " checked "  value = " Daily "   /> < input type = " checkbox "  name = " newsletter "   checked = " checked "  value = " Monthly "   />  ]
var check 
=  $( " input:checked " );  // 得到所有被选中的checkbox
   var actor_config;               // 定义变量
   check.each(function(i){          // 循环拼装被选中项的值
    actor_config  =  actor + ' , ' + $( this ).val();
    });
   alert(actor_config.substr(
9 ) + ' , ' );
通过以下js代码去获取选中项的值,在IE7中可以正确取得选中项的值,但在IE8中却得不到选中项的值,同样在Firefox 
3.5 .3下也得不到值,但公司同事在Firefox其他较低版本下能正确得到值,IE6下也没有问题,⊙﹏⊙b汗
$(
' #permissionList-body input[name="checkboxes"][checked] ' ).each(function(i){
 alert($(
this ).val());
});
      但是把技术代码修改为:
$(
' #permissionList-body input[name="checkboxes"] ' ).each(function(i){
 
if ( this . checked )alert($( this ).val());
});
===========================================================================
$(
' #permissionList-body input[name="checkboxes"][checked] ' )
$(
' #permissionList-body input[name="checkboxes"][checked= ' checked ' ] ' )
这两种写法支持IE
$(
' #permissionList-body input[name="checkboxes"][checked= ' true ' ] ' )

这种支持firefox

没有找到好的解决方法,只有加if(
this . checked )判断了

 

你可能感兴趣的:(checkbox)