开发者

How do I loop through a menu in jQuery?

I was wondering how I can loop through html menus with jQuery just like in text fields e.g.

$("#table input['type=te开发者_如何学运维xt']").each(function(){

});

How do I do the same for drop down menus?


Just change the selector to match the elements in the <select> element, which are <option> elements:

$("#select option").each(function(){

});


To loop through your menu items or any element just specify which class or element you want to loop through.

List:

$("#menu li").each(function(){
    alert($(this).val()); // Alert demonsatrating option value
});

Dropdown's

$("#menu option").each(function(){
    alert($(this).val()); // Alert demonsatrating option value
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜