사용자가 좋아하거나 좋아하지 않는 기사를 쉽게 처리 할 수있는 버튼을 개발해야합니다. 사용자가 버튼을 클릭하면 버튼이나 배경의 색상이 오렌지색으로 바뀌어야하고 기사를 즐겨 찾기에 추가하지 않으면 버튼의 색상이 사라집니다.Jquery의 즐겨 찾기 및 unfavorite 버튼이 작동하지 않습니다.
다음은 현재 Jquery에서 구현 한 내용이지만 한 번만 작동합니다. 바인딩은 두 번째로 처리되지 않습니다.
요소를 두 번째로 만들 때 바인딩을 다시 처리해야한다고 가정하지만 정확히 처리 할 위치가 확실하지 않습니다.
$('.colorStar').bind('click', function() {
var id = $(this).parent().parent().parent().parent().attr('id');
var removeElement = $(this).parent();
$(removeElement).empty();
$("<button data-action='show-contribute-how-to' class='btn colorStarred show'><i class='icon-star'></i></button>")
.click(function(){
var id = $(this).parent().parent().parent().parent().attr('id');
var removeElement = $(this).parent();
$(removeElement).empty();
$(removeElement).append("<button data-action='show-contribute-how-to' class='btn colorStar show'><i class='icon-star'></i></button>");
}).appendTo(removeElement);
$.ajax({
type : "POST",
url : "starNote",
data : {
id : id
}
});
});
HTML
<a class="star"><button class="btn colorStar hide" data-action="show-contribute-how-to"><i class="icon-star"></i></button></a>
그런 구체적인 도움이 필요하면 http://jsfiddle.net/ – mreq
을 작성하십시오. 완료, http://jsfiddle.net/SLq8W/ – shashank