简体   繁体   中英

innerHTML tag option doesn't work in IE9

My code:

    this.d.innerHTML = "";
    this.d.innerHTML += "<option value='-1'>Selecciona Distrito</option>";
    this.d.innerHTML += "<option value='santiagodesurco'>Santiago de Surco</option>";
    this.d.innerHTML += "<option value='sanborja'>San Borja</option>";
    this.d.innerHTML += "<option value='independecia'>Independencia</option>";
    this.d.innerHTML += "<option value='miraflores'>Miraflores</option>";
    this.d.innerHTML += "<option value='santanita'>Santa Anita</option>";

The problem is that the select tag in IE9 the tag option is ignored check it out:

http://i.stack.imgur.com/IolyV.png

But in Chrome the tag option is displayed:

http://i.stack.imgur.com/sfbDS.png

That's my problem, thanks in advance.

I solved my problem for each tag option i do:

        var opt = document.createElement('option');
        opt.text = 'Santiago de Surco';
        opt.value = 'santiagodesurco';
        document.getElementById('dropdown3').options.add(opt);

That way I fix the problem, so the code works in IE9.

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