$("input[class^=map]") not work for dropdown box in jquery
Does anyone know how can I get the ID and class name from the dropdown box in jquery? I have been using the following code
var my_array = array[];
$("input[class^=map]").each(function(index, element) {
my_array.push(this.id + "-" + this.className);
});
to get the ID and class name from the following code. This is working fine for TextBox but not dropdown box. Does anyone know what is it going on here? and how can I solve this issue?
<asp:TextBox ID="test" runat="server" MaxLength="12"开发者_如何学Python Width="3em" CssClass="mapTest" />
<asp:DropDownList ID="test1" runat="server" DataSourceID="dsTestType" CssClass="maptest1"
DataValueField="test_code" DataTextField="test_desc" AppendDataBoundItems="true" >
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
I would like the end result be like this:
my_array[0] = test-maptest
my_array[1] = test1-maptest1
I think it doesn't work, because DropDownList is generated as a:
<SELECT .....>
Instead of what you are looking for with jQuery:
<INPUT...>
try
$(":input[class^=map]").each(function(index, element) {
my_array.push($(this).attr("id") + "-" + $(this).attr("class"));
});
Change your selector
$("[class^=map]").each(function(index, element) {
my_array.push($(this).attr('id') + "-" + $(this).attr('class'));
});
精彩评论