如何用JS控制复选框选中时显示A图片 取消时显示B图片
展开全部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
//准备两张图片tupian1.jpg和tupian2.jpg
function tab(){
var val=document.getElementById("a1").value;
if(val==2){
document.getElementById("imga").src="tupian1.jpg";
document.getElementById("a1").value=1;
}else{
document.getElementById("imga").src="tupian2.jpg";
document.getElementById("a1").value=2;
}
}
</script>
</head>
<body>
<input type="checkbox" value="1" id="a1" onclick="tab()" />
<img src="tupian1.jpg" id="imga" />
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
//准备两张图片tupian1.jpg和tupian2.jpg
function tab(){
var val=document.getElementById("a1").value;
if(val==2){
document.getElementById("imga").src="tupian1.jpg";
document.getElementById("a1").value=1;
}else{
document.getElementById("imga").src="tupian2.jpg";
document.getElementById("a1").value=2;
}
}
</script>
</head>
<body>
<input type="checkbox" value="1" id="a1" onclick="tab()" />
<img src="tupian1.jpg" id="imga" />
</body>
</html>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询