jQuery UI를 사용하여 "이 작업을 정말로 수행 하시겠습니까?"라고 묻는 대화 상자를 표시합니다. 사용자가 하이퍼 링크 또는 양식 단추를 클릭 할 때jQuery UI 대화 상자가 기본값을 방지하고 버튼 클릭시 기본값을 다시 시작합니다.
사용자가 "확인"을 클릭하면 원래 기본 동작을 수행하려고합니다.
여기 내 코드입니다 :
[HTML]
<a href="page.htm">Click me</a>
[JQuery와]
// Global variable keeps track of whether the user has clicked confirm
var confirmed = false;
$("a").on("click", function(e) {
var self = $(this);
var options = {
autoOpen: true,
modal: true,
title: "Confirmation Required",
buttons : {
"Confirm" : function() {
// The user has confirmed, so set global variable to true
confirmed = true;
// Re-trigger the click
self.trigger("click");
},
"Cancel" : function() {
$(this).dialog("close");
}
}
};
// If the user hasn't yet confirmed, display the dialogue box
if (confirmed == false) {
$("<div />").text("Are you sure you want to do this?").dialog(options);
// Prevent the default action
e.preventDefault();
}
// Otherwise the user has confirmed, so don't preventDefault and return true
else {
confirmed = false;
// Alert here to check we reached this point
alert("Returning true");
return true;
}
});
먼저 링크를 클릭, 기본 동작을 방지하고 대화 상자가 열립니다.
대화 상자에서 "확인"을 클릭하면 클릭 이벤트가 다시 트리거되고 "돌아 오는 중"이라는 경고 상자가 나타납니다. 지금까지 모든 좋은, 그러나 페이지가로드되지 않습니다. 따라서 어떤 이유로 든 기본 이벤트 주변의 두 번째 시간은 여전히 방지되고 있으며 내 인생에서 그 이유를 알 수 없습니다.
그래도 괜찮습니다. 현재 그 방법을 사용하고 있습니다. 그러나 나는 또한 이것을 '