在从网站运行删除例程之前确认按钮 [英] Confirm button before running deleting routine from website

查看:94
本文介绍了在从网站运行删除例程之前确认按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有一个页面,它是使用来自SQL数据库的信息动态创建的。除了显示的数据外,还会为每个记录创建一个删除链接,该链接指向一个名为deleteRecord.php的php文件,该记录从数据库中删除该记录。



< img src =https://i.stack.imgur.com/3WjpV.pngalt =数据列表示例>



有什么方法可以合并一条确认消息,以便当单击删除链接时,只有在响应为是时才会运行deleteRecord.php文件?解析方案

p>你可以使用JavaScript。将代码嵌入到函数中或使用jQuery。


  1. 内联:

     < a href =deletelinkonclick =return confirm('Are you sure?')>删除< / a> 


  2. 在一个函数中:

     < a href =deletelinkonclick =return checkDelete()>删除< / a> 

    然后将它放在< head>

     < script language =JavaScripttype =text / javascript> 
    函数checkDelete(){
    return confirm('Are you sure?');
    }
    < / script>

    这个有更多的工作,但是如果列表很长,文件的大小会减少。


  3. 使用jQuery:

     < a href =deletelinkclass = 删除 >删除< / A> 

    把它放在< head>

     < script src =http://code.jquery.com/jquery-1.11.1.min.js >< /脚本> 
    < script language =JavaScripttype =text / javascript>
    $(document).ready(function(){
    $(a.delete)。click(function(e){
    if(!confirm('Are you sure?' )){
    e.preventDefault();
    return false;
    }
    return true;
    });
    });
    < / script>



I have a page on my website that is dynamically created with information from an SQL database. As well as the data being displayed a delete link is also created for each record which links to a php file called deleteRecord.php that deletes that record from the database.

Is there any way I can incorporate a confirmation message so that when the Delete link is clicked it will only run the deleteRecord.php file if the response is Yes?

解决方案

You could use JavaScript. Either put the code inline, into a function or use jQuery.

  1. Inline:

    <a href="deletelink" onclick="return confirm('Are you sure?')">Delete</a>
    

  2. In a function:

    <a href="deletelink" onclick="return checkDelete()">Delete</a>
    

    and then put this in <head>:

    <script language="JavaScript" type="text/javascript">
    function checkDelete(){
        return confirm('Are you sure?');
    }
    </script>
    

    This one has more work, but less file size if the list is long.

  3. With jQuery:

    <a href="deletelink" class="delete">Delete</a>
    

    And put this in <head>:

    <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script language="JavaScript" type="text/javascript">
    $(document).ready(function(){
        $("a.delete").click(function(e){
            if(!confirm('Are you sure?')){
                e.preventDefault();
                return false;
            }
            return true;
        });
    });
    </script>
    

这篇关于在从网站运行删除例程之前确认按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆