使用jquery设置asp.net下拉列表中的选定值

使用jquery设置asp.net下拉列表中的选定值,jquery,asp.net,jquery-ui,twitter-bootstrap,drop-down-menu,Jquery,Asp.net,Jquery Ui,Twitter Bootstrap,Drop Down Menu,我有一个代码,在asp.net dropdownlist上设置一个选定的值应该可以很好地工作,但由于某种原因,它不想在我的情况下工作,尽管它在我一直从事的其他项目中正常工作。 这是下拉列表: <asp:DropDownList ID="ddlPerc" runat="server"> <asp:ListItem Value="">Select Percentage</asp:ListItem>

我有一个代码,在asp.net dropdownlist上设置一个选定的值应该可以很好地工作,但由于某种原因,它不想在我的情况下工作,尽管它在我一直从事的其他项目中正常工作。 这是下拉列表:

  <asp:DropDownList ID="ddlPerc" runat="server">
                             <asp:ListItem Value="">Select Percentage</asp:ListItem>
                             <asp:ListItem Value="0.01">0.01</asp:ListItem>
                             <asp:ListItem Value="0.05">0.05</asp:ListItem>        
                 <asp:ListItem Value="0.1">0.1</asp:ListItem>  
                             <asp:ListItem Value="0.15">0.15</asp:ListItem>
                             <asp:ListItem Value="0.2">0.2</asp:ListItem>    
                             <asp:ListItem Value="0.25">0.25</asp:ListItem>  
                             <asp:ListItem Value="0.3">0.3</asp:ListItem>   
                             <asp:ListItem Value="0.4">0.4</asp:ListItem>                                                                
                             <asp:ListItem Value="0.48">0.48</asp:ListItem>                                                                  
                             <asp:ListItem Value="0.5">0.5</asp:ListItem>
                             <asp:ListItem Value="0.52">0.52</asp:ListItem>      
                             <asp:ListItem Value="0.6">0.6</asp:ListItem>
                             <asp:ListItem Value="0.7">0.7</asp:ListItem>
                             <asp:ListItem Value="0.75">0.75</asp:ListItem>                                                                  
                             <asp:ListItem Value="0.8">0.8</asp:ListItem>                                 
                             <asp:ListItem Value="0.85">0.85</asp:ListItem>    
                             <asp:ListItem Value="0.9">0.9</asp:ListItem>                                 
                             <asp:ListItem Value="0.95">0.95</asp:ListItem>
                             <asp:ListItem Value="0.99">0.99</asp:ListItem>
                             <asp:ListItem Value="1">1</asp:ListItem>
                             </asp:DropDownList>
当我检查页面的来源时,我可以看到该值已将标记选择为true,但在模式弹出窗口中,该值仍然未被选择。 你知道原因是什么吗? 提前谢谢你,拉齐尔

试试看

.prop('selected', true);
而不是

.attr('selected', true);
试试这个


CssClass
添加到
DropDownList
(例如
ddl
),并使用
$(“.ddl”).val(“您的值”)设置值

假设他使用的是jQuery 1.6或更高版本,是的,我使用的是jQuery 1.8.3,但仍然不想工作。如果有人有时间,他们可以连接到我的电脑,看看它到底是什么样子
.attr('selected', true);