一、局部改變樣式
分為改變直接樣式,改變className和改變cssText三種。需要注意的是:
注意大小寫:
javascript對大小寫十分敏感,className不能夠把“N”寫成“n”,cssText也不能夠把“T”寫成“t”,否則無法實現(xiàn)效果。
調(diào)用方法:
如果改變className,則事先在樣式表中申明類,但調(diào)用時不要再跟style,像document.getElementById('obj').style.className=”…”的寫法是錯誤的!只能寫成:document.getElementById('obj').className=”…”
改變cssText
但是如果用cssText的話,必須加上style,正確的寫法是:document.getElementById('obj').style.cssText=”…”
改變直接樣式我就不必說了,大家記得要寫到具體樣式即可,如
復制代碼 代碼如下:
document.getElementById('obj').style.backgroundColor=”#003366″
復制代碼 代碼如下:
<head>
<title>文檔標題</title>
<link rel=stylesheet type="text/css">
</link></head>
復制代碼 代碼如下:
< ? xml-stylesheet type="text/css" ?>
復制代碼 代碼如下:
<html>
<head>
<title>文檔標題</title>
<style type="text/css">
<!--
body {font: 10pt "Arial"}
h1 {font: 15pt/17pt "Arial"; font-weight: bold; color: maroon}
h2 {font: 13pt/15pt "Arial"; font-weight: bold; color: blue}
p {font: 10pt/12pt "Arial"; color: black}
-->
</style>
</head>
<body>
</body></html>
復制代碼 代碼如下:
<p>這一行被增加了左右的外補丁</p><p> </p>
新聞熱點
疑難解答
圖片精選