更改图像来源的一部分 [英] Changing part of image's source
本文介绍了更改图像来源的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想问一个问题,jQuery是否有可能更改图像来源的一部分? HTML代码很简单,例如
I want to ask question is there possible way with jQuery to change a part of images' source ? The HTML code is simple as
<img src="numbers/gray/1.png" alt="green" width="44" height="46" />
<img src="numbers/gray/5.png" alt="green" width="44" height="46" />
,因此[有两个文件夹'/gray/'和'/green/'],我可以(例如,单击链接变成绿色")来更改源的"/gray/"部分使用"/green/",同时保留来源的每个个人信息.
and so[there are two folders '/gray/' and '/green/'], can I just (as an example clicking on link"Become green") to change the part "/gray/" of the source with "/green/" while keeping each personal end of the source.
推荐答案
只需尝试以下操作:
$(function(){
$('#myLink').click(function(){
$('img').each(function(){
var $this = $(this)
$this.attr('src',$this.attr('src').replace('gray','green'))
})
})
})
这篇关于更改图像来源的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文