遍历< select>选项 [英] Iterate through <select> options
本文介绍了遍历< 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);
});
- http://api.jquery.com/each/
- http://jsfiddle.net/Rx3AP/
- http://api.jquery.com/each/
- http://jsfiddle.net/Rx3AP/
这篇关于遍历< select>选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文