- 정보공유
[JQUERY] 이미지 src replace
[code]
$(".btntype").click(function (){
$(".btntype").each(function(){
$(this).attr('src', $(this).attr('src').replace('_on.gif','.gif'));
});
var file = $(this).attr('src').split('/');
var filename = file[file.length-1];
var path = '';
for(i=0 ; i < file.length-1 ; i++){
path = ( i == 0 )?path + file[i]:path + '/' + file[i];
}
$(this).attr('src',path+'/'+filename.replace('.gif','_on.gif'));
});
[/code]
$(".btntype").click(function (){
$(".btntype").each(function(){
$(this).attr('src', $(this).attr('src').replace('_on.gif','.gif'));
});
var file = $(this).attr('src').split('/');
var filename = file[file.length-1];
var path = '';
for(i=0 ; i < file.length-1 ; i++){
path = ( i == 0 )?path + file[i]:path + '/' + file[i];
}
$(this).attr('src',path+'/'+filename.replace('.gif','_on.gif'));
});
[/code]