如何使用jQuery获取内部样式表?

时间:2018-07-24 04:29:10

标签: javascript jquery html css

任何人都可以告诉我如何使用jQuery获取内部样式表。我知道如何获得问候类的风格,但我想获得世界一流的风格。

<!DOCTYPE html>
<html>
<head>
	<style type="text/css">
		.hello{
			color: red;
		}
		.world{
			color: blue;
		}
	</style>
</head>
<body>
    <p class="hello">Hello world!</p>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

<!DOCTYPE html>
<html>
<head>
    <style type="text/css">
        .hello{
            color: red;
        }
        .world{
            color: blue;
        }
    </style>
</head>
<body>
    <p class="hello">Hello</p> 
    <p class="world">world!</p>
</body>
</html>

答案 1 :(得分:0)

您定义为.hello类,但.world类未声明如何在一个类属性中响应两种颜色

基于Jquery,您可以参考

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<title>Page Title</title>

</head>
<body>

 <p class="hello">Hello world!</p>
 </body>
</html>

<script>
 $(document).ready(function(){ 

    var n = $(".hello").length;

    if (n < 2) {
        $(".hello").css("color", "red");
       $(".hello").css("background", "blue");

    } 
    else {
        $("body").css("color", "orange");
    }

});

</script> 

检查下面的链接here

相关问题