Jquery - 嵌套循环中的 $(this)
我不知道如何在 Jquery 中做某事。假设我有一个包含许多选择下拉菜单的表单,并执行此操作...
$('#a_form select').each(function(index) {
});
在这个循环内时,我想循环每个选项,但我不知道如何执行此操作,是这样的吗? ...?
$('#a_form select').each(function(index) {
$(this + 'option').each(function(index) {
//do things
});
});
我无法完全让它工作,有建议吗?干杯。
I can't figure out how to do something in Jquery. Let's say I have a form with many select drop-downs and do this...
$('#a_form select').each(function(index) {
});
When inside this loop I want to loop over each of the options, but I can't figure out how to do this, is it something like this....?
$('#a_form select').each(function(index) {
$(this + 'option').each(function(index) {
//do things
});
});
I can't quite get it to work, and advice? Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信你想写
$('option', this)
。您还可以编写
$(this).find('option')
。I believe you want to write
$('option', this)
.You can also write
$(this).find('option')
.我会尝试
I would try
您需要考虑 self 变量的范围
You need to take into account the scope of the self variable