![](/img/trans.png)
[英]can i create custom confirm box in pure javascript (without using jquery) work same as window.confirm?
[英]Using jquery / javascript to create a popup confirm box
这是删除时如何创建一个confim框的摘录代码,
对于html部分:链接是触发JS代码,但它将同时触发php代码
对于JS部分:会触发popupbox
对于php部分:处理sql查询,应该可以
问题是:
我应该使用js触发php页面?但是我如何让php页面知道我要删除的ListID?
我应该在html链接中放什么?
谢谢
html
<a id="delete" href='delete.php?id=$set[ListID]'>Delete</a>
s
$(function(){
$("#delete").click(function() {
$.messager.alert('Warning','The warning message');
$.messager.confirm('Confirm','Are you sure you want to delete record?',function(r){
if (r){
alert('ok');
}
});
});
});
的PHP
//connection db
INSERT INTO delete_list SELECT * FROM list WHERE ListID=?;
INSERT INTO delete_user_list SELECT * FROM user_list WHERE ListID=?;
INSERT INTO delete_require_attributes SELECT * FROM require_attributes WHERE ListID='2';
INSERT INTO delete_subscriber SELECT * FROM subscriber WHERE ListID=?;
INSERT INTO delete_subscriber SELECT * FROM subscriber WHERE ListID=?;
DELETE FROM list WHERE ListID = '1'
如果我想在弹出框中包含列表名称怎么办?例如,是否要删除列表A,其中列表A已经是变量。 唯一的事情是如何将其附加到弹出框
"<tr><td>".$set['ListName']."</td><td>"
我不知道$ .messager做什么,但是我想这应该可以工作
$(function(){
$("#delete").click(function(evt) {
evt.preventDefault();
var urlscript = this.href; /* read link url (e.g. delete.php?id=314159) */
$.messager.alert('Warning','The warning message');
$.messager.confirm('Confirm','Are you sure you want to delete record?',function(r){
if (r) {
$.ajax(urlscript); /* make ajax call to that url with the right id */
}
});
});
});
我认为您的源代码实际上显示的是smthg
<a id="delete" href='delete.php?id=314159'>Delete</a>
因此在ajax调用中,您正在发送该ID。
尝试这个:
if (confirm("Question?")) {
// IF OK CLICKED
$.get('delete.php?id=MyID', function(data) {
alert('List DELETED');
});
}
$("#delete").click(function(e) {
e.preventDefault();
var url = this.href;
$.messager.confirm('Confirm','Are you sure you want to delete record?',function(r){
if (r){
location.href = url;
}
});
让该链接触发javascript代码以显示弹出窗口以进行删除确认。 同时,您可以使用所选的项目ID更新页面中隐藏字段的值。 当用户通过单击确认框中的“是”按钮确认删除时。 读取隐藏输入的值,然后将其发布到服务器(php)页面以从数据库中进行实际删除。
我不会将ID作为GET发送,否则人们可以增加值并删除您的记录?
<a class="delete" id="someId" >Delete</a>
$('.delete').click(function() {
var id = $(this).attr('id');
$.messager.alert('Warning','The warning message');
$.messager.confirm('Confirm','Are you sure you want to delete record?',function(r){
if (r) {
$.post('delete.php', {id:id}, function(response) {
//check the status of the reponse
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.