我遇到元素选择问题,我有一个表单,我想为每个表单each
框运行select
函数,这是我的代码:
$("#profile_form select").each(function(i){
var seen = {};
$(this + 'option').each(function() {
var txt = $(this).text();
if (seen[txt])
$(this).remove();
else
seen[txt] = true;
});
});
现在我的问题在于$(this + 'option')
部分,如果我尝试仅选择选择菜单它工作正常,但我需要选择option
如果我这样做我得到:
Uncaught Error: Syntax error, unrecognized expression: [object HTMLSelectElement]option
我做错了什么?
答案 0 :(得分:2)
$(this + "option")
尝试将字符串添加到DOM元素,这可能不是您想要的。您可能正在寻找:
$(this).find("option")
或者,或者:
$("option", this)
答案 1 :(得分:2)
试试这个
$('option', this).each(...)