去掉body背景图片的方法:1、用css(),语法“$("body").css("background","none");”;2、用attr(),语法“$("body").attr("style","background:none");”。

本教程操作环境:windows7系统、jquery1.10.2版本、Dell G3电脑。
jquery去掉body背景图片的方法
方法1:使用css()
css() 方法返回或设置匹配的元素的一个或多个样式属性。
利用css() 方法直接给background属性添加新值“none”,设置新样式即可。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="js/jquery-1.10.2.min.js"></script>
<style>
body{
background: url(img/2.png) no-repeat;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
$("button").click(function() {
$("body").css("background","none");
});
});
</script>
</head>
<body>
<button>去掉body背景图片</button>
</body>
</html>
方法2:使用attr()
使用attr()设置style属性,添加background:none样式,覆盖旧样式。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="js/jquery-1.10.2.min.js"></script>
<style>
body{
background: url(img/2.png) no-repeat;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
$("button").click(function() {
$("body").attr("style","background:none");
});
});
</script>
</head>
<body>
<button>去掉body背景图片</button>
</body>
</html>
【推荐学习:jQuery视频教程、web前端视频】
以上就是jquery怎么去掉body背景图片的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号