对象不支持此属性或方法与IE 8的问题

时间:2013-06-24 09:06:24

标签: jquery

嗨,网络上的好人,我对下面的脚本有疑问。

我一直在object doesn't support this property or method方法上遇到.length问题。有任何想法吗 ?

THX 杰伊

$('input:hidden').each(function(){
    var name = $(this).attr('name');
    if($("[name='"+name+"']").length >1){
        if($(this).attr('type')!=='radio' && $(this).attr('type')!=='submit' 
                                          && $(this).attr('type')!=='button' 
                                          && $(this).attr('type')!=='text'
                                          && $(this).attr('type')!=='checkbox'
                                          && $(this).attr('type')!=='select'){
            $(this).remove();
        }
    }
});

4 个答案:

答案 0 :(得分:0)

尝试使用size()代替length

$("[name='"+name+"']").size()

答案 1 :(得分:0)

您确实需要解决重复的基本问题,而不是破解导致的错误。

那说:虽然 Internet Explorer(至少8个)在单个输入字段上没有长度属性, IE8中的jQuery 1.10 将在两者上都返回1。长度和.size()所以你需要给我们更多的信息,并显示一些HTML

<!DOCTYPE html>
<html>
<head>
<title>Test length</title>
<script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
<script>
$(function(){
    $.each(["test1","test2"],function(i,name) {
      var input = $("input[name="+name+"]");
      var dotlength = input.length;
      var size = input.size();
      window.console && console.log("input.length:",dotlength);
      window.console && console.log("input.size():",size);  
  });
});
</script>
</head>
<body>
<input name="test1" /><hr>
<input name="test2" /><br><input name="test2" /><br>
</body>
</html>

在IE中给出:

LOG: input.length:1
LOG: input.size():1
LOG: input.length:2
LOG: input.size():2

答案 2 :(得分:0)

不需要检查这些内容,请尝试使用以下代码:

$(document).ready(function() {
    $('input:hidden').each(function(){
      var name = $(this).attr('name');
      $("[name='" + name + "']").slice(1).remove();
    });
});

答案 3 :(得分:0)

既然你说你很新。您可以为多个表单使用以下任何插件,这样就可以避免Browser compatibility issues并使代码保持清洁

http://mstratman.github.io/jQuery-Smart-Wizard/
http://wbotelhos.com/stepy
http://thecodemine.org/