【发布时间】:2020-11-25 16:30:06
【问题描述】:
我在 asp.net 表单中有这个下拉列表/组合框/选择元素:
<asp:DropDownList
ID="_ddlMode"
runat="server"
AppendDataBoundItems="true"
ClientIDMode="Static"
CssClass="input_medium"
DataSourceID="_sdsModes"
DataTextField="description"
DataValueField="id">
<asp:ListItem Selected="True" Text="None" Value="" />
</asp:DropDownList>
当用户更改所选元素时,我需要调用函数SetModes()。
我试过这个:
$(function () {
$(document.body).on('change', '_ddlMode', function () {
var _index = $("select[id='_ddlMode'] option:selected").index();
SetModes(_txtBank, _txtZip, _index);
});
});
没有运气。然后我尝试了这个:
$(function () {
_ddlMode= $("input[id$='_ddlMode']");
_ddlMode.change(
function () {
var _index = $("select[id='_ddlMode'] option:selected").index();
SetModes(_txtBank, _txtZip, _index);
}
);
});
再次没有运气......错误在哪里? 在事件处理中检索所选元素的索引是否有更有效的方法?
附:我正在使用jquery-.2.1.3,jquery-ui-1.11.2
【问题讨论】:
-
$(document.body).on('change', '_ddlMode',->$(document.body).on('change', '#_ddlMode',或$(document.body).on('change', "select[id='_ddlMode']",因为你在下一行有这个,暗示你可能多次使用同一个 ID。
标签: javascript jquery asp.net