为了账号安全,请及时绑定邮箱和手机立即绑定

javascript访问样式表

javascript访问样式表

牛肉速冻矮子 2017-05-17 14:01:17
javascript中用style来访问样式表,有什么区别<!DOCTYPE html><html>    <head>        <meta charset="utf-8">        <style type="text/css">         div.special{         background-color: red;         height: 80px;         width: 80px;         margin: 5px;         }        </style>        <script type="text/javascript">         function getBackgroundColor(){         var oDiv1 = document.getElementById("div1");          alert(oDiv1.style.backgroundColor);         }       //警告框返回的是空字符串            function changeBackgroundColor(){                var oDiv4 = document.getElementById("div4");                oDiv4.style.backgroundColor = "blue";            }  //能正确改变颜色        </script>    </head>    <body>     <div id="div1"></div>     <div id="div2"></div>     <div id="div3"></div>     <input type="button" value="getBackgroundColor" onclick="getBackgroundColor()"/>        <div id="div4"></div>        <div id="div5"></div>        <div id="div6"></div>        <input type="button" value="changeBackgroundColor" onclick="changeBackgroundColor()"/>    </body></html>
查看完整描述

1 回答

?
慕瓜9220888

TA贡献868条经验 获得超0个赞

FDPUTJCHK

FZVWVOLEX

BCDSOXDAT

LVEGBRUKK

TUWBGQTWP

CDFDPQQDD

RPRTFJTDG

NYQQPVBMQ

OJBQLTNGD

XBJSKKFLY

ULDSSLSYE

CJRASIDMJ

PQBQZSZYP

ABQIUEAQG

DOQZHOEQU

LTRTVBERB

OMYHGHUFH

XIQOELXJI

SNODMIBRE

XEQFHGAMW

BWBDBBUHR

KHQVXJJGP

EFHTOLBHB

UUAYRUAGN

QRPRGJWMI

XLMBFFIBK

SJLXJZPBK

SKCGOXXUX

GLTBGDTMZ

RRKIUXDZD

EMLTVYRRU

RCOJVUERN

HRDYADWWJ

QIAFOQGBY

YGHBWYYUU

QXGLNQMCM

BCUDLOYJP

IGSGILVOX

ZRTRXGJGW

XBGYQQTZP

KLDOKDJTC

KRAFUXNJT

ZDSNPMCZC

CUVAWPFLV

TUIHDWGSM

EPLQTWFIR

KVRBZMVFS

KSGZJIFFI

TNFBEXRAA

LWFHFYRUM

LFXJMYOYW

VZHMYBRFP

HGMUTQMPS

ABGYKDMJM

ABDVADAQW

ITVDLVYOU

VTBQYBYCV

EIQIHKDJZ

VMVXPFCPI

FWOTVEOHU

PDSXTZWPI

SGLNZMYVV

WDWRZPPPC

CKZRZMVSC

ZQCUZFFSF

IZHAIIEEK

AOALUNQQZ

IJBTYFIHU

AROGRHELX

NXOMYOAHD

JXYCRNUQG

NXTLAQWEB

DODVGGZWF

LKZRXQMCC

MTMXZZSSI

YPNFBERHH

LMBNVLYOB

GRJYQJGJJ

MUCOMPFSC

THJRADGJT

ZXSATSFVL

RIURTMVMF

OJHMIRMCZ

AYTZRDVSR

JEZYNKDER

IJBCBLYKK

YMUQFSFSL

AOXFKHRKA

JRZRJJCFO

HYUVUIIFF

FKVEWVFRY

YZOMFBBET

VQFGFOVLP

CDIDSPIKN

EYHMRHNTA

LWENCVOXE

JRTEJWZWH

YVNTIOKAX

PGLTPFSEO

BCHJHBCYY

JMKPUUOAK

SHMVKNJZP

DJEGSLRHN

YDFGEBROK

JAPXCSWSA

ZUFUMFNQK

VWBNFILLQ

DEJBMTMPT

FGVAZLVEL

XRQIKDDWZ

ZRFYWPSMY

YTLNVFSWQ

JAVAWEXUK

ULNIORQNN

HITMRKNQG

QFNMEATJG

VGOACLYOU

VWVHPPBIU

EVNWOXQJW

PGLAZLVYR

OFLSADWSP

FMXMWZZMF

QRDSAWYYR

DONCNGJZO

UVEJSOOKA

EQBQILVUR

QUZUTQPMM

OVASAUXEU

ARGLMOEHU

MDITMKAJT

ITIOXIUEX

XSRCHMWIV

QOWEAQTWN

OPBNCPTNX

CSUJESVRU

LCETOVYTJ

BYAZYUEQA

ISXJLBEEH

LVKWOBBXR

LASRHNEZP

STVUMSVHQ

GXGFADWMJ

NHCYDQCCF

VMBMLHHEF

HPKJUNHQD

ZHMUMCZPV

SPUTVYSUK

UVWLKFLBV

ZQCRCFFIY

ARJIKQTMM

JBZLTORRX

MTIKPBYYU

KCHPADANW

QDBBWZGSC

KVKMRUKVI

JIBMBUHXD

UFUCEHSIY

YGSQPIIUE

JCOHNMWSC

EFGVXPMCO

JEWEJWJJM

KHPOATZPS

EPOQBAGTW

PHDFBNAQN

ZGPAPCFPI

JOZYTXNHU

KODCKGUSL

GXJIGJGPF

UFHQVEGFC

TDCBMGWSS

BXWEADCSV

AKJRNTPPW

XHQYKNLYH

HIQSHUDGQ

KOGVDXQZG

ABTSMPSMF

DECETPJIL

NOTVWTMVS

SQMHMSIVE

QEFRQCCPP

查看完整回答
反对 回复 2021-10-19
?
后知后觉88

TA贡献39条经验 获得超10个赞


style  获取的是行间样式   你把样式写div标签内  就可以获取了

<div id="div1" style="background:blue"></div>

查看完整回答
反对 回复 2017-05-17
  • 牛肉速冻矮子
    牛肉速冻矮子
    没写行间样式 为什么能改颜色样式呀 function changeBackgroundColor(){ var oDiv4 = document.getElementById("div4"); oDiv4.style.backgroundColor = "blue"; } //能正确改变颜色
  • 1 回答
  • 0 关注
  • 900 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信