Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript,如何更改内部css类的值_Javascript_Css_Stylesheet - Fatal编程技术网

Javascript,如何更改内部css类的值

Javascript,如何更改内部css类的值,javascript,css,stylesheet,Javascript,Css,Stylesheet,我有一个带有内部css样式标记的html文件,其中包括css类,我试图在窗口宽度小于700时更改名为“header1”的类中的颜色值: <script type="text/javascript"> var width = document.body.clientWidth; if (width <=700){ var hColor = document.getElementsByTagName("st

我有一个带有内部css样式标记的html文件,其中包括css类,我试图在窗口宽度小于700时更改名为“header1”的类中的颜色值:

        <script type="text/javascript">

        var width = document.body.clientWidth;

        if (width <=700){
            var hColor = document.getElementsByTagName("style").item("header1").style.color;
               alert(hColor);

        }
    </script>

var width=document.body.clientWidth;

如果(宽度),请添加你的(相关的)HTMLForget JavaScript。只需使用CSS。(参见重复问题中的第二个)。我尝试了getElementsById,getElementsByTagName,没有一个有用的,正如我说的,我是JavaScript新手。你应该阅读CSS中的媒体查询:你可以根据屏幕分辨率操作更改元素的样式。对不起。。
<DOCTYPE! html>
<head>

    <style type="text/css" name="myStyle">

        body {

            margin:0%;
            padding:0%;
            background-color:#c9d2d9;

        }

        .div {
            width:75%;
            height:auto;
            margin:2em auto;

        }

        .nested-div{
            width:100%;
            height:auto;
            margin:2em auto;
        }

        .header1{
            width:100%;
            text-align: center;
            font-family: 'Lobster', cursive;
            color: aquamarine;


        }

    </style>

    <script type="text/javascript">

        var width = document.body.clientWidth;

        if (width <=700){
            var hColor = document.styleSheets[0].rules;
            alert(hColor[0].slectorText);

        }
    </script>

</head>

<!--------------------------------------------- BODY ---------------------------------------------->

<body>

    <div class="div">


        <div class="nested-div">

            <h1 class="header1">                
                 Some Text
            </h1>