javascript创建一个弹出

javascript创建一个弹出

本文介绍了使用jquery / javascript创建一个弹出确认框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是如何在删除时创建confim框的提取代码,

对于html部分:
链接将触发JS代码,但它会同时触发php代码

对于JS部分:
popupbox被触发


对于PHP部分:
处理sql查询,应该没问题的。



问题是:


  1. 我应该使用js来触发php页面吗?但是我怎样才能让php页面知道我要删除哪个ListID?


  2. 我应该在html链接中输入什么?


谢谢



html

 < a id =deletehref ='delete.php?id = $设定[ListID]'>删除< / A> 

Js

  $(function(){
$(#delete)。click(function(){
$ .messager.alert('Warning','The warning message');
$ .messager.confirm('确认','你确定要删除记录?',函数(r){
if(r){
alert('ok');
}
});
});
});

php

  //连接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函数(evt){
evt.preventDefault();
var urlscript = this.href; / *读链接url(例如delete.php?id = 314159)* /

$ .messager.alert('Warning','The warning message');
$ .messager.confirm('确认','您确定要删除记录吗?',function(r){
if(r){
$ .ajax(urlscript); / *使用正确的ID对该网址进行ajax调用* /
}
});
} );
});

我假设您的源代码实际上显示的是smthg,如

 < a id =deletehref ='delete.php?id = 314159'>删除< / a> 

所以在ajax调用您发送该id。


Here is the extract code of how to make a confim box when delete,

For html part:A link is to trigger JS code , but it will trigger the php code at same time

For JS part:popupbox is triggered

For php part:Process the sql query, it should be ok

The problem are:

  1. I should use js to trigger the php page?But how can i let the php page know that which ListID i want to delete?

  2. What should i put in the html link?

Thank you

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'

What if i want to include the list name in the popup box e.g. do you want to delete list A ,where list A is a variable already. The only thing is how can i append it to the popup box

"<tr><td>".$set['ListName']."</td><td>"
解决方案

I don't know what $.messager does, but I suppose this should work

$(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 */
        }
    });
 });
});

and I supposing that your source code is actually showing smthg like

<a id="delete" href='delete.php?id=314159'>Delete</a>

so on the ajax call you're sending that id.

这篇关于使用jquery / javascript创建一个弹出确认框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 13:40