为什么这个javascript不能连续切换css样式?
1个回答
展开全部
<!DOCTYPE html>
<html>
<head>
<title> New Document </title>
<link id="mylink" href="" rel="stylesheet" type="text/css">
<meta charset="utf-8" />
<style type="text/css">
body{
margin:0;
padding:0;
}
</style>
</head>
<body>
<input type="button" onclick="setCSS()" id="test" value="setCSS"/>
<script tyle="text/javascript">
var mycss = document.getElementById("mylink"),
turnback=false;
function setCSS(){
mycss.href = turnback?"stylesheet1.css":"stylesheet2.css";
turnback = !turnback;
}
</script>
</body>
</html>
感觉你想要的是这样的效果
<html>
<head>
<title> New Document </title>
<link id="mylink" href="" rel="stylesheet" type="text/css">
<meta charset="utf-8" />
<style type="text/css">
body{
margin:0;
padding:0;
}
</style>
</head>
<body>
<input type="button" onclick="setCSS()" id="test" value="setCSS"/>
<script tyle="text/javascript">
var mycss = document.getElementById("mylink"),
turnback=false;
function setCSS(){
mycss.href = turnback?"stylesheet1.css":"stylesheet2.css";
turnback = !turnback;
}
</script>
</body>
</html>
感觉你想要的是这样的效果
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询