你好,我试图使用autocomplete dropdownlist插件,名称是ufd。 无论如何,我有dropdownlist,我想要在代码隐藏click_event上得到这个选定的值(或文本)。 如果我可以从下拉列表中删除所有选定的ATTR,并添加选择的ATTR到所选的选项,这将work.But这removeAttr不工作:(请帮我jquery removeAttr无法正常工作
$(function() {
var element = $("#DropDownList1");
$(element).change(function() {
$(element).find('option').removeAttr('selected'); //this is not working
$(element + "option[value=" + $(element).val() + "]").attr("selected", "selected");
});
});
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
代码隐藏:
protected void Page_Load(object sender, EventArgs e)
{
using (TalepService tService = new TalepService())
{
DropDownList1.DataSource = tService.ddlTalepDurumDoldur();
DropDownList1.DataTextField = "talepDurumu";
DropDownList1.DataValueField = "talepDurumID";
DropDownList1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string text = DropDownList1.SelectedItem.Text;
string value = DropDownList1.SelectedValue;
}
你为什么要这么做?它看起来像发生“变化”时,您手动执行浏览器自动执行的操作。我的意思是如果发生“变化”事件,那么选定的选项将会被更改。 – 2012-01-17 21:19:14
我回答了贾斯珀我在想什么。我不知道为什么,但当我选择任何选项(更改),看不到这是在萤火虫上选择。这就是为什么我想手动去获得代码隐藏的这个值。问题仍在继续:) – blackraist 2012-01-17 21:54:30
你是什么意思,你看不到它被选为萤火虫?如果你想要这个值,只需要执行'$(this).val()',但是不应该有任何理由去操作属性。 – 2012-01-17 21:58:13