开发者

$("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'));
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜