我想用JS激活CSS。假设我有这个代码,并且我想在第一次点击时放大图片,然后在第二次点击后将其发送到右侧,但它不起作用。功能是否正确?如何与JS一起使用CSS
如何使用JavaScript控制元素的CSS?
<script>
function function(){
var house = document.getElementById("house");
if(this.className == "mystyle")
this.className = "mystyle2";
else
this.className = "mystyle";
}
</script>
<a href="#" style="text-decoration: none"><img src="casa1.jpg" id="house" width="200" height="150" onclick="function()">
我想它来激活这个CSS:
.mystyle {
position: absolute;
left: 50%;
margin-left: -100px;
}
.mystyle2{
float: right;
}
您不能给函数名称“function”。如果您检查(您应该),您应该在浏览器控制台中看到一个错误。 – Pointy
我编辑它,即时通讯有一个不同的名字。 – Angelo
不是真的重复。因为我不知道如何使该功能在第二次点击时做其他事情。 – Angelo