http://jsfiddle.net/Xtreu/ 링크를 참조하여 모든 양식을 사용하지 않고 "내 데이터 삭제"버튼 이벤트에서 동일한 기능을 수행하려고합니다. 나는 다른 방법으로 시도했지만 일어난 일이 아닙니다. 클릭 이벤트와 함께 동일한 예제를 수행하는 방법을 알려줄 수 있습니까?클릭시 이벤트를 수행 할 수 없습니다.
HTML :
<form method="post" action="/echo/html/">
<input type="hidden" name="html" value="<p>Your data has been deleted</p>" />
<input type="submit" value="Delete My Data" />
</form>
<div id="confirmBox">
<div class="message"></div>
<span class="button yes">Yes</span>
<span class="button no">No</span>
</div>
자바 스크립트를
function doConfirm(msg, yesFn, noFn) {
var confirmBox = $("#confirmBox");
confirmBox.find(".message").text(msg);
confirmBox.find(".yes,.no").unbind().click(function() {
confirmBox.hide();
});
confirmBox.find(".yes").click(yesFn);
confirmBox.find(".no").click(noFn);
confirmBox.show();
}
$(function() {
$("form").submit(function (e) {
e.preventDefault();
var form = this;
doConfirm("Are you sure?", function yes() {
form.submit();
}, function no() {
// do nothing
});
});
});
, 그것은 어떤 형태의 태그없이입니다 -> HTTP : //jsfiddle.net/Xtreu/445/ 어쩌면 당신은 폼이없는 버튼을 원하기 때문에 잘못되었거나 코드에서 작동하지 않는 것이 무엇인지 확인하십시오. 예제 코드에는 폼이 있습니까? – Eich