Stupid IE not showing selected value in combo box

北城以北 提交于 2019-12-25 05:11:55

问题


I am facing a weird problem in IE which is not happening with other browsers. Open the following website:

http://www.clinicasdefertilidadenlima.pe/

You will see 3 combo boxes on this page displaying "Lima". Click on any combo and select any other value like Lima or Arequipa. Page will refresh but now combo will not show selected value which should always be "Lima" (I have hard coded it) If you take a look at the view source then it's a simple combo box and I have even defined selected="selected" for "Lima" value but in IE it only displays selected value when you open home page. After that it doesn't show value when you select value from combo box.

<select id="city_id" name="city_id" class="f2_city" onchange="redirect(this.form)">
    <option value="" selected="selected">LIMA</option>
    <option value="LIMA">LIMA</option>
    <option value="Arequipa">Arequipa</option>
</select>

I am using IE9.


回答1:


I solved using the jquery n-th:child selector that works on IE7/8/9 Chrome/Firefox etc.

var comboId = document.getElementById('YourDropDownListId');
var selectedIndex = comboId.selectedIndex;
var selector = '#TableName:nth-child(' + selectedIndex.toString() + ')';
var selectedTable = $(selector).val();



回答2:


I have fixed the issue. Just defined this in page.

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" >


来源:https://stackoverflow.com/questions/10508399/stupid-ie-not-showing-selected-value-in-combo-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!