以下是删除时如何制作confim框的提取代码,
对于html部分: 链接是触发JS代码,但它会同时触发php代码
对于JS部分: 弹出框被触发
对于php部分: 处理sql查询,应该没问题
问题是:
我应该用js来触发php页面?但是我怎么能让php页面知道我要删除哪个ListID?
我应该在html链接中添加什么内容?
谢谢
HTML
<a id="delete" href='delete.php?id=$set[ListID]'>Delete</a>
的js
$(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>"
答案 0 :(得分:1)
我不知道$ .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。
答案 1 :(得分:0)
试试这个:
if (confirm("Question?")) {
// IF OK CLICKED
$.get('delete.php?id=MyID', function(data) {
alert('List DELETED');
});
}
答案 2 :(得分:0)
$("#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;
}
});
答案 3 :(得分:0)
让链接触发javascript代码以显示删除确认的弹出窗口。同时,您可以使用所选的项目ID更新页面中隐藏字段的值。当用户通过单击确认框中的“是”按钮确认删除时。读取隐藏输入的值,然后将其发布到服务器(php)页面,从数据库中进行实际删除。
答案 4 :(得分:0)
我不会将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
});
});
});