2012-03-19 67 views
0

我有一個元素選擇一個問題,我有一個表格,我想運行每個窗體selecteach功能,這裏是我的代碼:jQuery的選擇元素錯誤

$("#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

試試這個

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

$(this + "option")嘗試向DOM元素添加字符串,這可能不是您想要的。你可能會尋找:

$(this).find("option") 

,或者:

$("option", this) 
+0

謝謝你,它的工作 – Linas 2012-03-19 22:18:53