我正在尋找一種方法,當用戶點擊鏈接時,從Asp ListItem中更改選項值。如何從Jquery的鏈接中更改選項值?
比如我有一個天冬氨酸列表項:
<asp:DropDownList ID="DropDownList1" runat="server" class="Preview_link"
Height="20px" Width="118px">
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>White</asp:ListItem>
<asp:ListItem>Green</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
</asp:DropDownList>
而且我有2個鏈接
<a href="#" title="red" class="preview_link">red</a>
<a href="#" title="white">white</a>
當用戶點擊紅色的選項將切換爲紅色和白色將切換爲白色。我正在使用下面的代碼,但它不工作。
我該如何去改變這個jQuery的工作與Asp ListItem而不是HTML下拉?
jQuery("a.preview_link").click(function() {
var title = jQuery(this).attr("title");
jQuery(this).parent('p').find("select option").filter(function() {
return $(this).text() == title;
}).attr('selected', 'selected'); });
沒有#DropDownList1。在asp.net中它將被翻譯成類似'#ctr01_ContentContainer_DropDownList1'的東西# –
但是這可能與$(「select.Preview_link ...」)一起工作 –
爲什麼id選擇器不能使用asp? – fatiDev