gpt4 book ai didi

javascript - 单击时如何使我更改为另一个图像的图像?

转载 作者:太空宇宙 更新时间:2023-11-04 11:29:16 26 4
gpt4 key购买 nike

我尝试使用 JavaScript,但我认为它用错了位置。到目前为止我有什么。

    <!doctype html>
<html>
<head>
<title>Public Vision</title>
<link rel="stylesheet" type="text/css" title="backbone" href="backbone.css">
<link rel="alternative stylesheet" type="text/css" title="alt" href="alt.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>

</head>
<body class="style2">
<div id="header" class="style2"><div id="header2" class="style2">Public Vision</div></div>
<iframe width="640" height="400"
src="https://www.youtube.com/embed/videoseries?list=PLX9_I-EOJPdFuOjcI2zkmTck55homHEBE"
frameborder="2" allowfullscreen></iframe>

<input id="showHideContainer" type="image" src="on.jpg " height="3%" width="2%" alt="On" onclick="toggle();changeImage();">
<script>
document.getElementById('showHideContainer').onclick = function () {
divTest = document.getElementById('header');
if (divTest.style.display === "none") {
divTest.style.display = 'block';
} else {
divTest.style.display = "none";
};
function changeImage() {
var image = document.getElementById('showHideContainer');
if (image.src.match("off")) {
image.src = "on.jpg";
} else {
image.src = "off.jpeg";
}
};
$('body').toggleClass('style2');
</script>
</body>
</html>

我想我将 JavaScript 用于在错误的位置点击更改图像或设置不正确,我们将不胜感激,或者如果您知道更好的方法来完成我想要的事情,那就太好了。提前致谢。

这也是我的 CSS:

  #header { height: 15%; width: 100%; background-color: white; z-index: 2; position: fixed; right:0; top:0;


box-shadow: 0 4px 4px -2px #232323;
-moz-box-shadow: 0 4px 4px -2px #232323;
-webkit-box-shadow: 0 4px 4px -2px #232323;
}

#header2{height: 15%; width: 100%; position: fixed; color:grey; opacity: 0.6; text-align: center; z-index: 4; font-size: 30px; margin-top: 2.5%; background-color:clear;}
iframe {display:block; margin: 0 auto; margin-top: 17%;}


body{
background-color:#404040; z-index:3; transition: background-color 2s;
}
body.style2{
background-color:white; z-index:3;
}

最佳答案

http://jsfiddle.net/9jwnoxcr/

先决条件:jQuery

HTML:

<img id="imgTarget" src="http://www.hdwallpapersimages.com/wp-content/uploads/2014/01/Winter-Tiger-Wild-Cat-Images.jpg">

Javascript:

$('#imgTarget').click(function(){
$('#imgTarget').attr('src', 'http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg');
});

关于javascript - 单击时如何使我更改为另一个图像的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32147970/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com