1
내 문제에 도움을 주시면 감사하겠습니다. 그 같은 20-30 요소가 : .file 블록의 CSS 스타일링에 사용jQuery/Tags 입력 - 내용으로 요소를 선택하십시오.
<div class="file file-unchosen">
<div class="file-name-title">
"File-title"
</div>
</div>
난 bootstrap tags input list I 기능을 가진 파일을 선택 저장할 수있다 :
$('.file').click(function() {
$(this).toggleClass('file-unchosen file-chosen');
function addWork(elem) {
var workname = $(elem).find('.file-name-title').text();
$('#chosen-works-list').tagsinput('add', workname);
};
addWork(this);
});
문제는 필자가 태그 입력 목록에서 .file을 제거 할 때 .file을 선택 취소하는 방법을 이해할 수 없다는 것입니다. 지금은 (어쨌든 작동하지 않습니다)이 같은 중간에 있어요 : (. .file 이름 파일 선택) $ 같다 $는 .text() 경우
이론적으로$('#chosen-works-list').on('itemRemoved', function(event) { //when tag is removed from tags list
var chosenWorks = [];
$('.file-chosen').each(function(i,elem) { //we take all of the chosen files
console.log(elem); //log them
chosenWorks.push($(elem).find('.file-name-title').text().toString());
}); //push them to array
var delWork = event.item; //define deleting tag
...and I don't know what to do next..
});
, 다음 단계는 확인해야합니다 (delWork) 클래스를 토글하지만이를 수행하는 방법을 알아낼 수는 없습니다.
$('.file[data-content="'+ delWork +'"]').toggleClass('file-unchosen file-chosen');
망가 데이터 속성을 사용하는 것을 주저하고, 그들에 의해 쿼리
<div class="file file-unchosen" data-content="deleted-tag-content">
다음이처럼 행동 :