星期五, 十月 10, 2008

好站: CSS 屬性 與 JavaScript 對應 轉換表

CSS 的屬性值 和 JavaScript 設定 CSS 屬性值 的命名規則上有點差異, 簡單的說, 大多數的差異, 都是 CSS 屬性有 -: 號的, 就是去掉 -:, 後面接的字轉大寫, ex:

  • background-color => backgroundColor
  • background-image => backgroundImage
  • background-position => backgroundPosition
  • background-repeat => backgroundRepeat
  • text-decoration: line-through => textDecorationLineThrough
  • text-decoration: none => textDecorationNone
  • 要注意的例外狀況是: float => styleFloat 這個.

CSS 屬性 與 JavaScript 的轉換對照表

另外若有使用 jQuery 的, 雖然 jQuery 幫我們做很多簡化, 不過 .css() 這個方法, 還是照這個規則走(本來是希望可以 'background-color' 設. XD), 這個對照表還是記起來比較好~ .css 的方法是照這個規則走, 如果要使用 'background-color', 要用 " 括起來.

  • jQuery 使用範例:
  • $("a").css({backgroundColor:"yellow", fontWeight:"bolder"});
  • $("a").css({"background-color": "yellow", "font-weight": "bolder"});

相關網頁

延伸閱讀

相關標籤

this is comment icon [回覆]

其實 jQuery.css() 可以辦的到...

$("a").css({
"background-color": "yellow",
"font-weight": "bolder"
});

使用有屬性裡面出現 - 符號的時候, 前後加上引號就可以了...

Comment by 裝笑幃 (10/10/2008 13:17)

this is comment icon 回 裝笑幃 [回覆]

原來如此, 感謝指點.. Orz..

Comment by Tsung (10/10/2008 22:19)
Add this page to del.icio.us

發表迴響

標題

內容 (限制 1000 字)

暱稱

電子郵件

個人網頁


 authimage


PS: 若無法留言, 請先確認是否有打開 JavaScript, 造成您的困擾, 實在萬分對不起 Orz...(如果無法留言, 勞煩可以發信給我好嗎? 謝謝.)
PS2: 若您的留言被誤判, 我都會再自行看過, 不需要一直重覆張貼~