e.preventDefault();를 추가하려고합니다. 태그를 클릭하면 아래 코드는 작동하지만 작동하지 않습니다. 누군가 제게 조언 해주세요. 고맙습니다.e.preventDefault() in Javascript 프로토 타입 모듈 패턴
(function($){
'use strict';
var ItemPhoto = function(){
this.$el = undefined;
this.getElements();
this.events();
}
ItemPhoto.prototype = {
getElements: function(){
this.$el = $('#contaner').find('.image');
this.$item = $('#contaner').find('.item').find('a');
},
events: function(){
this.$item.on('click', {_self:this}, this.swapImage());
},
swapImage: function(e){
e.preventDefault();
var _self = e.data._self;
_self.$el.attr('src', _self.$item.attr('href'));
}
}
var itemPhoto = new ItemPhoto();
})(jQuery);
'()'덕택에'swapImage'를 이벤트 핸들러에 바인딩하는 것이 아니라 호출하고 있습니다. – ssube
좋아, 내가 언급 한 줄을 편집했지만 여전히 작동하지 않습니다. – shinyatk
[귀하의 편집으로 인해 문제가 해결되었습니다.] (https://jsfiddle.net/rx96ma6d/). 그래서 롤백하고 복제본으로 닫습니다. – Oriol