我尝试从另一个下拉列表(ddlColor)中传入值,并将其选定的id和文本值传递给ddlEngine的事件方法
<asp:DropDownList ID="ddlEngine" runat="server" onchange="GetSearchResults(ddlColor.value, ddlColor.text, this.options[selectedIndex].text);" />我想我不能像这样引用ddlColor,我的语法中有一些不正确的地方,我看不到是什么。
这是我的尝试:
这是在我的页面顶部js标记之后全局定义的:
var ddlColor = document.getElementById('<%=ddlColor.ClientID %>');
var colorid_dropdown = ddlColor.options[ddlColor.selectedIndex].value;
var colorname_dropdown = ddlColor.options[ddlColor.selectedIndex].text;然后,在下拉列表的更改中,我尝试将其附加到调用中:
onchange="GetSearchResults("' + colorid_dropdown + ", " + "'colorname_dropdown + '" + ", this.options[selectedIndex].text);" 发布于 2011-11-05 04:29:49
尝试使用DropDownList的ClientID属性:
var ddl = document.getElementById('<%= ddlColor.ClientID %>');更新:
在更新的代码示例中,您似乎没有像使用ddlCar那样将ddlColor放入JS变量中。这会是你的问题吗?
发布于 2011-11-05 04:53:24
在页面顶部将其定义为全局
var ddlColor = document.getElementById('<%=ddlColor.ClientID %>');这是您的ddlEngine下拉菜单
<asp:DropDownList ID="ddlEngine" runat="server" onchange="GetSearchResults(ddlColor.value, ddlColor.options[ddlColor.selectedIndex].text, this.options[selectedIndex].text);"></asp:DropDownList>https://stackoverflow.com/questions/8015281
复制相似问题