問題,我使用的是這樣的:http://docs.jquery.com/UI/AutocompletejQuery用戶界面自動完成 - 訪問id屬性
我初始化這樣的(部分代碼)文本框:
$('#foo').autocomplete
{
source: function()
{
// How to get the id of the element?
}
}
在source
回調,我需要知道當前元素的id是什麼。在這個例子中,顯然是foo
;在實際應用中,選擇器是動態分配的,所以我不知道id
是什麼。
我看着下面:
console.debug($(this)); // displays [a.widget.a]
console.debug($(this.id)); // displays []
console.debug($(this).attr('id')); // displays undefined
如何獲得元素的ID?
有效'id'可以」從一個數字開始。 – alex
糟糕,你是對的。我會修復我的例子。 – StackOverflowNewbie