简体   繁体   中英

Problem with IE

I have the following code:

function header(){
 experience += '';
 var expimage = '';
 for(var cik=0;cik<experience.length;cik++){
  switch(experience[cik]){
   case '0':
   expimage += 'img0';
   break;
   case '1':
   expimage += 'img1';
      break;
      case '2':
      expimage += 'img2';
      break;
      case '3':
      expimage += 'img3';
      break;
      case '4':
      expimage += 'img4';
      break;
      case '5':
      expimage += 'img5';
      break;
      case '6':
      expimage += 'img6';
      break;
      case '7':
      expimage += 'img7';
      break;
      case '8':
      expimage += 'img8';
      break;
      case '9':
      expimage += 'img9';
      break;
  }
 }
 document.getElementById('level').innerHTML = expimage;
 alert(expimage);
}

But it only work on chrome or mozilla. It shows up an empty alert box, but it work on firefox and chrome. I tried to alert each variable after each line, and I noticed that the problem shows when I tried to alert(experience[0]) ,it shows undefined, the other steps are working.

Could you show the full code and HTML so I can see how you are calling this method and how 'experience' is defined?

Also, It looks like you could replace your switch statement with this:

expimage += 'img' + experience[cik];

The variable experience doesn't seem to be defined anywhere before it is used. You probably want to pass it into the function as an argument; you can modify your function to accept the argument like this:

function header(experience) {
    // ....
}

Without more information on what experience is and the code that is calling header , it's difficult to answer your question more thoroughly.

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