遍历< select>选项 [英] Iterate through <select> options

查看:53
本文介绍了遍历< select>选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在HTML中有一个<select>元素.该元素代表一个下拉列表.我试图了解如何通过JQuery遍历<select>元素中的选项.

I have a <select> element in HTML. This element represents a drop down list. I'm trying to understand how to iterate through the options in the <select> element via JQuery.

如何使用JQuery在<select>元素中显示每个选项的值和文本?我只想在alert()框中显示它们.

How do I use JQuery to display the value and text of each option in a <select> element? I just want to display them in an alert() box.

推荐答案

$("#selectId > option").each(function() {
    alert(this.text + ' ' + this.value);
});

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆