当用户单击链接时,我正在寻找一种方法来更改 Asp ListItem 的选项值。
例如我有一个 Asp ListItem:
<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'); });