您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

JavaScript访问Css

2024/3/29 19:55:23发布10次查看
html+js代码:
   <!doctype html public "-//w3c//dtd html 4.01 transitional//en"
"http://www.w3c.org/tg/xhtml/dtd/xhtml-transitional.dtd">
<html>
  <head>
    <title>changecolor.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="http://www.php1.cn/">     <script type="text/javascript">
        function changecolor(eventobj){
            //获得css中的所有选择器
            var cssset = document.stylesheets[0].rules;
            //从css中获取所需要的选择器
            var style1=cssset[0];
            if(eventobj.value==黑色){
                style1.style.backgroundcolor=black;
            }else if(eventobj.value==红色){
                style1.style.backgroundcolor=red;
            }
        }
    </script>
  </head>
  <body>
    <div class="style1"></div>
    <input type="button" value="黑色" onclick="changecolor(this);">
    <input type="button" value="红色" onclick="changecolor(this);">
  </body>
</html>
css代码:
.style1{
    width: 600px;
    height: 400px;
    background-color: black;
}
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product