function deletePost(id) {
var db_id = id.replace("post_", "");
// Run Ajax request here to delete post from database
document.body.removeChild(document.getElementById(id));
}
function CustomConfirmPop() {
this.render = function(dialog, op, id) {
var winW = window.innerWidth;
var winH = window.innerHeight;
var dialogoverlay = document.getElementById('dialogoverlay');
var dialogbox = document.getElementById('dialogbox');
dialogoverlay.style.display = "block";
dialogoverlay.style.height = winH + "px";
dialogbox.style.left = (winW/2) - (550 * .5) + "px";
dialogbox.style.top = "100px";
dialogbox.style.display = "block";
document.getElementById('dialogboxhead').innerHTML = "Confirm that action";
document.getElementById('dialogboxbody').innerHTML = dialog;
document.getElementById('dialogboxfoot').innerHTML = '<button type="button" onclick="Confirm.yes(\'' + op + '\',\'' + id + '\')">Yes</button> <button onclick="Confirm.no()">No</button>';
}
this.no = function() {
document.getElementById('dialogbox').style.display = "none";
document.getElementById('dialogoverlay').style.display = "none";
}
this.yes = function(op, id) {
if (op == "delete_post") {
deletePost(id);
}
document.getElementById('dialogbox').style.display = "none";
document.getElementById('dialogoverlay').style.display = "none";
}
}
var Confirm = new CustomConfirmPop();
<div id="dialogoverlay"></div>
<div id="dialogbox">
<div>
<div id="dialogboxhead"></div>
<div id="dialogboxbody"></div>
<div id="dialogboxfoot"></div>
</div>
</div>
<p id="post_1">
Today is a lovely day ...
<button onclick="Confirm.render('Delete Post?','delete_post','post_1')">Delete</button>
</p>
<script>
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
var r = confirm("You Want to Remove??");
if (r == true) {
e.preventDefault(); $(this).parent('div').remove(); x--;
}
});
});
//how can i use this code and apply my css styling to it becuase this works to some extent?
</script>
確定,所以當我點擊刪除應該有一個確認彈出框,詢問是或否刪除帖子之前。問題是當我點擊刪除它只是選擇是自己沒有我得到機會點擊它或沒有。我不知道它是否與我的html頁面中的其他按鈕衝突。
它工作正常的我。在你的問題中,你錯過了'
'。我糾正了在製作堆棧片段時,原始頁面中是否存在該錯誤? – Barmar
我想把它放在一個動態生成的輸入字段使用jQuery。確認用戶是否要刪除該字段 – Lee
請參閱http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements – Barmar