简体   繁体   中英

Using eval() not work in IE8 and IE 7 but works in IE9, FF,Chrome?

I have problem regarding eval(), i'm validating the data that the user submit using a object javascript..

Eg

for(var i=0;i<count;i++){

     switch(caseType){
       case: 'Group':
        ### it will execute the ff code
        ### it will call MustChecked function

        if(!eval(this.MustChecked(getAttribute('class'), getAttribute('min'), getAttribute('max')))) {

           ####this will alert all the errors..
          this.AddError(i, getAttribute("msg"));
        }
     }


}

From this code, it will alert all errors... This code is not Working in IE8 and IE7... Anyone have an idea why is not working in IE8 and IE7?

UPDATED: MUSTCHECKED FUNCTION

 MustChecked : function(name, min, max) { var groups = document.getElementsByClassName(name); alert(groups); //console.log(name + ":" + groups.length); var hasChecked = 0; min = min || 1; max = max || groups.length; for(var i=groups.length-1;i>=0;i--) if(groups[i].checked) hasChecked++; return min <= hasChecked && hasChecked <= max; }, 

UPDATE V1.1

I tried like this

getElementsByClassName : function (className) {
        if (document.getElementsByClassName) { 
          return document.getElementsByClassName(className); 
        }
        else { 
            return document.querySelectorAll('.' + className); 
        } 
},

This work in IE8 but not in IE7... any luck?

The getElementsByClassName method is not supported in IE7/8. And you use it in your MustChecked function.

Not supported as in "doesn't exist".

There are shims available. Quickly googling will give your some results. Or you could use Sizzle or simply a querySelectorAll shim, which are much more generic.

If you want to find out if a feature is supported, a good resource is caniuse.com .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM