这是我的代码
<div style="text-align:center;">
<div class="ghor" id="a" onclick="chek_mark()"></div>
function call
</div>
<script type="text/javascript">
function chek_mark(){
var el= document.getElementById("a").style.background-image;
if (el.url("Black-Wallpaper.jpg"))
{
el.url = "cross1.png";
}
else if(el.url("cross1.png"))
{
alert("<h1>This is working too.</h1>");
}
}
</script>
我想使用if else条件语句更改背景图片。
this is the style-sheet
.ghor //this is the div class
{
background-image: url('Black-Wallpaper.jpg');
background-size: cover;
border-radius: 5px;
height: 100px;
width: 100px;
box-shadow: 2px 5px 7px 7px white;
/*background-color: black;*/
display:inline-block;
}
var el= document.getElementById("a").style.background-image;
怎么能工作?属性中有一个减号... 我本以为应该是var el= document.getElementById("a").style.backgroundImage;
。 - MDickten