Inside my form, I've declared dropdows the following way:
Html.DropDownList(String.Format("Record[{0}].Action", i), new[]
{
new SelectListItem { Text="Ajustar Quantidade", Value= ((int)InventoryGoodsActionEnum.AdjustQuantity).ToString()},
new SelectListItem { Text="Relocalizar", Value= ((int)InventoryGoodsActionEnum.AdjustLocation).ToString(), Selected=true},
new SelectListItem { Text="Ajustar Quantidade e Relocalizar", Value= ((int)InventoryGoodsActionEnum.AdjustQuantityLocation).ToString()},
new SelectListItem { Text="Ignorar", Value= ((int)Inv开发者_如何学GoentoryGoodsActionEnum.Ignore).ToString()},
})
Now I'd like to be able to get all of them (they will be multiple because the id increases) with jquery so I can iterate through them. How can I do this?
Use a tag/element selector and an attribute starts-with selector, like this:
$("select[name^='Record[']")each(function() {
//do something
});
This will select all dropdowns with a name="Record[...."
to loop through. If necessary you can add a ends-with selector as well, like this:
$("select[name^='Record['][name$='].Action']")each(function() {
//do something
});
精彩评论