Jquery选择元素错误

时间:2012-03-19 22:12:39

标签: jquery

我遇到元素选择问题,我有一个表单,我想为每个表单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

我做错了什么?

2 个答案:

答案 0 :(得分:2)

$(this + "option")尝试将字符串添加到DOM元素,这可能不是您想要的。您可能正在寻找:

$(this).find("option")

或者,或者:

$("option", this)

答案 1 :(得分:2)

试试这个

 $('option', this).each(...)