여러 행이있는 양식이 있으며 각 행에는 링크가있는 삭제 버튼이 있습니다. 부트 스트랩 모달을이 버튼에 추가하는 링크를 점차적으로 향상시키고 싶습니다. 그래서 내가하고있는 일은 다음과 같습니다.각 클릭에 클릭 이벤트가 추가됩니다.
- 페이지의 모든 삭제 버튼 요소를 가져옵니다.
- 각 버튼을 반복합니다.
- "OK"가 클릭되었을 때 호출되는 URL을 포함하여 각 버튼에 대해 클릭 한 버튼에 따라 모달의 일부 속성을 변경합니다.
모달이 실행되고 "확인"버튼을 클릭 할 때마다 첨부 된 URL이 이전에 추가 된 것을 제외하고는 모든 것이 효과가 있습니다.
http://jsfiddle.net/bittersweetryan/9TpX8/
여기
//anonymous function to grab all delete buttons and turn into a modal
(function(){
var delBtn = $(".delete"),
$modal = $("#modal-delete");
if(!$modal.size()){
$modal = $('<div id="modal-delete" class="modal hide fade"><div class="modal-header"> <a href="#" class="close">×</a><h3>Confirm Delete</h3></div><div class="modal-body" id="modal-content"></div><div class="modal-footer"> <a href="#" id="okButton" class="btn danger">OK</a> <a href="#" id="cancelButton" class="btn secondary">Cancel</a> </div></div>').appendTo("body");
}
delBtn.each(function(){
var $button = $(this),
clickHandler,
href= $button.attr("href");
if(href){
clickHandler = function(){
console.log(href);
//return window.location=href;
};
}
else{
clickHandler = $button.click;
}
$button.attr("data-toggle","modal").
attr("data-target","#modal-delete");
$button.on("click",function(){
$modal.find("#okButton").on("click",function(){
clickHandler();
$modal.modal('hide');
}).
end().
find("#cancelButton").on("click",function(){
$modal.modal('hide');
}).
end().
find("#modal-content").html($button.attr("title"));
});
});
})();
덕분에, 나는 하나 개의 기능에 대한 API 문서를 읽을 필요거야. 그 존재를 몰랐습니다. – bittersweetryan