2013-04-28 73 views
0

我想添加多個HTML中的HTML標籤的屬性使用.attr()但我發現了以下錯誤在我的螢火控制檯:得到錯誤使用.attr添加多個屬性()

SyntaxError: missing : after property id 
[Break On This Error]  
aria-selected: true, 
#PrizeBondSearch (line 149, col 22) 

這裏是代碼我試過了:

$('ul.k-group').find('a[href="#' + url + '"]').addClass('k-state-selected k-state-focused').parent().attr({ 
    aria - selected: true, 
    id: 'panelbar_pb_active' 
}); 

我不知道爲什麼我得到這個錯誤或如何解決它。 如果還有其他更好的方法,我會很高興知道它。

回答

3

我認爲這是你設置的「詠歎調選」的方式 - 「 - 」,因爲它包含了你應該使用引號:

{ 
    "aria-selected": true, 
    id: 'panelbar_pb_active' 
} 
2

正確synthax是:

$('ul.k-group').find('a[href="#' + url + '"]').addClass('k-state-selected k-state-focused').parent().attr({ 
      "aria-selected": true, 
      id: 'panelbar_pb_active' 

     }); 

見詠歎調選擇的包裹在雙引號(或者可以是單引號)。

1

需要引用aria-selected,因爲它在它-

相關問題