0
내 script이 작동하지 않는 이유를 모르겠다. div 클래스를 변경하고 클래스 이름으로 elem에 바인드 된 이벤트를 수신하려고합니다.업데이트 된 클래스가있는 요소에 이벤트 수신기를 추가하는 방법은 무엇입니까?
$('.glyphicon-minus').on('click', function() {
var item = $(this).closest('.item');
var child = $(item).children('.item-content');
$(child).hide();
$(this).removeClass('glyphicon glyphicon-minus').addClass('glyphicon glyphicon-plus');
});
$('.glyphicon-plus').on('click', function() {
var item = $(this).closest('.item');
var child = $(item).children('.item-content');
debugger;
$(child).show();
$(this).removeClass('glyphicon glyphicon-plus').addClass('glyphicon glyphicon-minus');
});
아,'$ ('glyphicon-plus') 대신에 쓸 때 'click', function() {...})'이 줄'$ (document) .on ('click' , .glyphicon-plus ', function() {...})'모두 잘 동작합니다. – barbara