求一段点击按钮两张图片互换的js
点击按钮图1变成图2,再点击又变回来<script>functionchange_pic(){varimg1=document.images["pic1"];varimg...
点击按钮图1变成图2,再点击又变回来
<script>
function change_pic(){
var img1=document.images["pic1"];
var img2=document.images['pic2'];
if(img1.src==img2.src){
img1.src="pic1.jpg";
}else{
img1.src=img2.src;
}
}
</script>
<form name="one">
<input type="button" name="but2" value="切换图片" onclick="change_pic()">
</form>
类似这样的 展开
<script>
function change_pic(){
var img1=document.images["pic1"];
var img2=document.images['pic2'];
if(img1.src==img2.src){
img1.src="pic1.jpg";
}else{
img1.src=img2.src;
}
}
</script>
<form name="one">
<input type="button" name="but2" value="切换图片" onclick="change_pic()">
</form>
类似这样的 展开
1个回答
展开全部
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
function change_pic(){
var img1=document.getElementById('img1'脊渣);
var img2=document.getElementById('img2');
temp = img1.src;
img1.src = img2.src;
img2.src = temp;
}
</script>
<input type="button" name="but2" value="切换樱晌悄图片" onclick="change_pic()">
<img id="img1" src="C:\Users\Administrator\Desktop\1.jpg" 谨瞎alt="" />
<img id="img2" src="C:\Users\Administrator\Desktop\2.jpg" alt="" />
</body>
</html>
我在桌面上放了两张图片,你也可以试试
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询