0

I have a drop down control in my web page. That's viewed Collection Dictionary value. Here i added One Option value in top of the drop down list with enabled selected option using J query.since the newly one added using [j query] was selected in drop down box after page render except the IE9,IE10 browser.

Please find the sample code.

collection code:

Dictionary<string,string> PlatformList=new Dictionary<string,string>();
PlatformList.Add("asp","ASP.NET")
PlatformList.Add("aspnetmvc","ASP.NET MVC")
PlatformList.Add("wpf","WPF")
PlatformList.Add("silverlight","Silverlight")

Here now binded the collection with drop down.

View.cshtml

  @Html.DropDownList("platform", new SelectList(PlatformList, "Key", "Value"))

Now i have added new Option in the Drop down with enabled selected option Using Jquery.

$(document).ready(function(){
  $('#platform').prepend("<option  value='all'>All</option>");
        $("#platform").find('option:first').attr('selected', 'selected'); 

});

After page rendered, The newly added one" All Option in selective stage in drop down' This is worked in IE7,IE8,Mozilla,Chrome.

But In IE9,IE10 the "All" option not viewed in U drop down.but it locate the top of the list with selected but it hide status.the viewed option in drop down was next to the All option is"

<option val="all" selected="selected">All</option>==> not viewed in IE9,IE10
<option val="asp">ASP.NET</option>----> this is viewed in IE9,IE10 in case the above issue.

please suggest can this support IE9,IE10. if so means, please update the solution.

4

2 回答 2

1

尝试这个:

$(document).ready(function(){
    $('#platform').prepend("<option  value='all'>All</option>");
    $("#platform option:selected").removeAttr('selected');
    $("#platform option:first").attr('selected', 'selected'); 
});

您的代码没有selected从原始默认值中删除该属性,并且具有此属性的多个选项可能会发生冲突。

于 2013-07-30T14:24:36.337 回答
0

手动更改索引也应该有效:

$( "#platform" )[ 0 ].selectedIndex = 0;
于 2013-11-26T00:04:53.967 回答