2013-04-28 29 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,因为它在它-

相关问题