Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过单击类中的图像更改图像_Javascript_Jquery_Html - Fatal编程技术网

Javascript 通过单击类中的图像更改图像

Javascript 通过单击类中的图像更改图像,javascript,jquery,html,Javascript,Jquery,Html,我在同一个班级有4张图片。如果我单击该类的某个图像,我想替换该图像,但仅替换该图像,而不替换同一类中的其他图像: <img src="1..." class="things"> <img src="2..." class="things"> <img src="3..." class="things"> <img src="4..." class="things"> 它什么也没做! 在我使用.hover()更改鼠标悬停时的图标图像之前!也许这就是

我在同一个班级有4张图片。如果我单击该类的某个图像,我想替换该图像,但仅替换该图像,而不替换同一类中的其他图像:

<img src="1..." class="things">
<img src="2..." class="things">
<img src="3..." class="things">
<img src="4..." class="things">
它什么也没做!
在我使用.hover()更改鼠标悬停时的图标图像之前!也许这就是问题所在

你错过了一些引语,我想:

$(".things").click(function(){
  $(this).attr('src', 'other_image.png');
})

你错过了一些引语,我想:

$(".things").click(function(){
  $(this).attr('src', 'other_image.png');
})

代码中几乎没有错误-将其更改为--




代码中几乎没有错误-将其更改为--




嘿,伙计,请检查一下这个代码

<script>
$("document").ready(function (){
$("img").click(function(){
$(this).attr('src', 'Blue hills.jpg');
});
});

$(“文档”).ready(函数(){
$(“img”)。单击(函数(){
$(this.attr('src','bluehills.jpg');
});
});

这对我来说很好。

嘿,伙计,请查看此代码

<script>
$("document").ready(function (){
$("img").click(function(){
$(this).attr('src', 'Blue hills.jpg');
});
});

$(“文档”).ready(函数(){
$(“img”)。单击(函数(){
$(this.attr('src','bluehills.jpg');
});
});

这对我来说很好。

对不起。。。我在这里写错了!我是我的代码,我有$(“.things”)!好啊我想我发现了错误!。。。是因为de.hover事件。因为在它的回调中,我再次更改了图像!!在我点击图片后,没有其他方法可以禁用悬停事件吗?我更新了答案并给出了演示。你能把
hover
handler的代码也贴出来吗?`$('.things').hover(function(){$(this).attr('src','./img/select_image.png');},function(){$(this.attr('src','./img/unselect_image.png');});好的。。查看答案中提到的最新小提琴。对不起。。。我在这里写错了!我是我的代码,我有$(“.things”)!好啊我想我发现了错误!。。。是因为de.hover事件。因为在它的回调中,我再次更改了图像!!在我点击图片后,没有其他方法可以禁用悬停事件吗?我更新了答案并给出了演示。你能把
hover
handler的代码也贴出来吗?`$('.things').hover(function(){$(this).attr('src','./img/select_image.png');},function(){$(this.attr('src','./img/unselect_image.png');});好的。。查看答案中提到的最新小提琴。对不起。。。我在这里写错了!我是我的代码,我有$(“.things”)!很抱歉我在这里写错了!我是我的代码,我有$(“.things”)<代码>
<script>
$("document").ready(function (){
$("img").click(function(){
$(this).attr('src', 'Blue hills.jpg');
});
});