Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript radiobutton在FF和Chrome中工作,但在IE中不工作_Javascript_Jquery_Internet Explorer_Google Chrome_Radio Button - Fatal编程技术网

Javascript radiobutton在FF和Chrome中工作,但在IE中不工作

Javascript radiobutton在FF和Chrome中工作,但在IE中不工作,javascript,jquery,internet-explorer,google-chrome,radio-button,Javascript,Jquery,Internet Explorer,Google Chrome,Radio Button,我必须验证radiobox是否已选中 HTML 鉴于您正在使用jQuery,您可以这样做: if ($(':radio[name="benvoor"]:checked').length === 0) { // none are checked, do something } 也就是说,找到该名称的所有选中单选按钮,如果生成的jQuery对象的长度为0,则不选中任何单选按钮 简单演示: 您不会显示太多html,但从JS来看,单选按钮似乎位于id为“radiobutton”的元素中,因此您可

我必须验证radiobox是否已选中

HTML


鉴于您正在使用jQuery,您可以这样做:

if ($(':radio[name="benvoor"]:checked').length === 0) {
   // none are checked, do something
}
也就是说,找到该名称的所有选中单选按钮,如果生成的jQuery对象的长度为0,则不选中任何单选按钮

简单演示:

您不会显示太多html,但从JS来看,单选按钮似乎位于id为“radiobutton”的元素中,因此您可能希望将其包含在jQuery选择器中:

if ($('#radiobutton :radio[name="benvoor"]:checked').length === 0) {

鉴于您正在使用jQuery,您可以这样做:

if ($(':radio[name="benvoor"]:checked').length === 0) {
   // none are checked, do something
}
也就是说,找到该名称的所有选中单选按钮,如果生成的jQuery对象的长度为0,则不选中任何单选按钮

简单演示:

您不会显示太多html,但从JS来看,单选按钮似乎位于id为“radiobutton”的元素中,因此您可能希望将其包含在jQuery选择器中:

if ($('#radiobutton :radio[name="benvoor"]:checked').length === 0) {

如果您仍在使用jquery,可能会使用@nnnnnn-answer,但在JSFIDLE中您的代码略有修改:

Chrome

0
1
-----
0
1
length
item
IE


因为在javascript imo中,in循环通常是导致问题的原因,请使用jquery's each之类的帮助程序或执行常规for循环,就像我在上面的示例中所做的那样。

如果您仍在使用jquery,可能会使用@nnnn-answer,但您的代码在JSFIDLE中略有修改:

Chrome

0
1
-----
0
1
length
item
IE


因为在javascript imo中,in循环通常会导致问题,所以请使用jquery的each之类的帮助程序,或者像我在上面的示例中所做的那样,执行常规for循环。

+1。是,切勿使用
for..in
迭代类似数组的对象(即具有
.length
属性和数字索引的对象)。对于循环或jQuery的$来说,一个普通的
。每个()
都是方法(或者如果您有一个实际的数组,而不仅仅是一个类似数组的对象)。+1。是,切勿使用
for..in
迭代类似数组的对象(即具有
.length
属性和数字索引的对象)。一个普通的
for
循环或jQuery的
$。each()
就是方法(或者如果您有一个实际的数组,而不仅仅是一个类似数组的对象)。
var arr = [1,2];
for(i in arr){
    console.log(i);    
}

console.log('-----');
for(i in frm.rdio){
    console.log(i);    
}
0
1
-----
0
1
length
item
0 
1 
------------ 
rdio 
length 
item 
namedItem