嗨,我正在使用以下代码通过 jquery 应用 css 的多个属性。我的代码是
$("div:contains('Awais')").css( {text-decoration : 'underline', cursor : 'pointer'} );
我收到 JavaScript 错误
missing : after property id
$("div:contains(John)").css( {text-dec...: 'underline', cursor : 'pointer'} );
但是当我删除 text-decoration
属性时,错误消失了。这段代码有什么问题
最佳答案
text-decoration
是无效的属性名称,除非它作为字符串括在引号中:
$("div:contains('Awais')").css( {'text-decoration' : 'underline', cursor : 'pointer'} );
对象属性必须用引号引起来,除非它们是有效的 Javascript 标识符。对于对象文字中的声明以及使用点表示法进行访问都是如此(因此 object.text-decoration
无效。
关于javascript - 这段 jquery 代码有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7469780/