jq设置css的方法:1、设置单个样式属性,代码为【$('#test').css('background-color','red')】;2、设置多个属性你,可以传入一个对象,代码为【$('#test').css({'background】。

本教程操作环境:windows7系统、css3版,DELL G3电脑。
jq设置css的方法:
如果要设置单个样式属性可以这样
$('#test').css('background-color','red');如果你要同时设置多个属性你,可以传入一个对象
立即学习“前端免费学习笔记(深入)”;
$('#test').css({'background-color':'red','font-size':'20px'});即属性值例如background-color,你也可以用驼峰形式backgroundColor,这时你可以不用单引号
你可以亲自试一下
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/<a href="http://www.jquerycn.cn/
" target="_blank" class="inner-link">jquery</a>/1.7.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $('#test').css('background-color','red');
  });
});
</script>
</head>
<body>
<h1 id="test">jquery 设置css</h1>
<button type="button">设置h1的css</button>
</body>
</html>相关教程推荐:CSS视频教程
以上就是jq如何设置css的详细内容,更多请关注php中文网其它相关文章!
 
                        
                        每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
 
                Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号