2011-09-19 67 views
0

嗨我正在使用以下代码通过jQuery应用css的多个属性。我的代码是这个jQuery代码有什么问题

$("div:contains('Awais')").css({text-decoration : 'underline', cursor : 'pointer'}); 

我得到JavaScript错误

missing : after property id 
$("div:contains(John)").css({text-dec...: 'underline', cursor : 'pointer'}); 

但是当我remoce text-decoration属性错误消失。什么是错的代码

+0

重新标记了这个问题。它与jQuery或选择器无关。 –

+0

@Felix Kling Thanks dude –

回答

4

text-decoration是一个无效的属性名称,除非它是用引号括起来作为一个字符串:

$("div:contains('Awais')").css({'text-decoration' : 'underline', cursor : 'pointer'}); 

对象属性必须用引号括起来,除非它们是有效的JavaScript标识符。这是在对象文字,也为使用点符号访问声明真实的(所以object.text-decoration无效

4

不能在JavaScript中使用未加引号的连字符,修改text-decoration使用textDecoration

$("div:contains('Awais')").css({textDecoration : 'underline', cursor : 'pointer'}); 

或者引用它:

$("div:contains('Awais')").css({'text-decoration' : 'underline', cursor : 'pointer'});