小知识:js如何更改css样式

<html>
<head>
<meta charset="utf-8">
<title>exp</title>
<style>
p{
  background-image:url(写你的图片url);
}
</style>
</head>
<body>
<p id="p"></p>
<a href="javascript:void(0);" onclick="hideImg()">点击我隐藏</a>
<a href="javascript:void(0);" onclick="showImg()">点击我显示</a>
<a href=" http://www.dadaxun.com/">达达寻</a>
</body>
</html>
<script>
function hideImg(){
var p = document.getElementById("p");
p.style.backgroundImage = "";
}

function showImg(){
var p = document.getElementById("p");
p.style.backgroundImage = "url(写你的图片url)";
}
</script>

原文地址:https://www.cnblogs.com/275147378abc/p/4501681.html