[英]what is wrong with this jquery code
嗨,我正在使用以下代碼通過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中未用引號引起來的連字符,而不能使用textDecoration
來修改text-decoration
:
$("div:contains('Awais')").css( {textDecoration : 'underline', cursor : 'pointer'} );
或引用它:
$("div:contains('Awais')").css( {'text-decoration' : 'underline', cursor : 'pointer'} );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.