당신이해야 할 일은 div의 클릭 핸들러 내부에서 이미지의 src를 변경하는 것입니다. 코드처럼 읽을 것, 그래서
jQuery('.expand-one').click(function(){
jQuery('.content-one').slideToggle('fast');
var img = $(this).find('img'),
src = img.attr("src")
alt = img.data("altsrc");
img.attr("src",alt).data("altsrc",src);
});
jQuery('.expand-one').toggle(function() {
jQuery('.content-one').slideDown('fast');
}, function() {
jQuery('.content-one').slideUp('fast');
});
또한보다 효율적인 방법은 클래스와 배경 이미지를 사용하는 것입니다 :
HTML
<div class="expand-one blue-icon"></div>
CSS
.expand-one { margin-left: 5px } /* Margin of Icon Size */
.blue-icon { background-image: url('blue-icon.png'); }
.green-icon { background-image: url('green-icon.png'); }
JS
//This turns one off and the other on
$(this).toggleClass('blue-icon green-icon');
오 마이 갓! 너는 구세주 야! 친절하게 대해 주셔서 감사합니다. 당신은 저에게 많은 분노를 구했습니다. 나를 2 분 안에 대답으로 표시 할 것입니다. –
나는 그 방법이 훨씬 더 마음에 든다. 고맙습니다! –