如何在单击按钮时显示jquery确认对话框?

问题描述 投票:0回答:1

我想在单击按钮时显示jQuery确认对话框。但是,当我加载页面时,它没有显示确认框。

    $(document).ready(function(){
        $(document).on("click","#remove",function () {
            let id = $(this).attr("value");
            Dialogify.confirm('Are you sure you want to remove data ?', {
                ok: function () {
                    Dialogify.alert('deleted');
                    $.ajax({
                        url: "remove_post.php",
                        type: "POST",
                        data: {
                            p_id: id
                        },
                        success: function (data) {
                            Dialogify.alert('deleted');
                            // alert(data);
                        }
                    })
                },
                cancel: function () {
                    this.close();
                }


            });


        });
    });
                <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>HomeShopping</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" >
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://www.jqueryscript.net/demo/Dialog-Modal-Dialogify/dist/dialogify.min.js"></script>
                </head>
<body>

<div class="container-fluid">
    <div class="row px-5">
        <div class="col-md-7">
            <div class="shopping-cart">
                <h6>My Cart</h6>
                <hr>

                <?php
                include("functions/functions.php");
                $total = 0;

                $ip_add = getRealIpUser();

                $select_cart = "select * from cart where ip_add='$ip_add'";

                $run_cart = mysqli_query($conn,$select_cart);

                while($row_cart = mysqli_fetch_array($run_cart)){

                    $pro_id = $row_cart['p_id'];

                    $pro_size = $row_cart['size'];

                    $pro_quantity = $row_cart['quantity'];

                    $get_products = "select * from products where no='$pro_id'";

                    $run_products = mysqli_query($conn,$get_products);

                    while($row_products = mysqli_fetch_array($run_products)){

                        $product_title = $row_products['product_title'];

                        $product_img1 = $row_products['product_img1'];

                        $only_price = $row_products['product_price'];


                        ?>
                        <form  method="post" class="cart-items">
                            <div class="border rounded">
                                <div class="row bg-white">
                                    <div class="col-md-3 pl-0">
                                        <img src="product_images/<?php echo $product_img1; ?>" alt="Image1" class="img-fluid">
                                    </div>

                                    <div class="col-md-6">
                                        <h5 class="pt-2"><?php echo $product_title; ?></h5>
                                        <small class="text-secondary">Seller: dailytuition</small>
                                        <h5 class="pt-2"><?php echo $only_price; ?></h5>
                                        <button type="submit" class="btn btn-warning">Save for Later</button>
                                        <button id="remove" type="submit" class="btn btn-danger mx-2" name="remove" value="<?php echo $pro_id;?>">Remove</button>
                                    </div>

                                    <div class="col-md-3 py-5">
                                        <button type="button" class="btn bg-light border rounded-circle" ><i class="fas fa fa-minus" ></i></button>
                                        <input type="text" id="<?php echo $pro_id?>" value="<?php echo $pro_quantity?>" class="form-controls w-25 d-inline">
                                        <button type="button" class="btn bg-light border rounded-circle" > <i class="fas fa fa-plus" ></i></button>
                                    </div>
                                </div>
                            </div>
                        </form>


                    <?php }}?>
            </div>
        </div>
    </div>
</div>
</body>

</html>

remove_post.php

    <?php
include ("conn.php");
global $conn;
if(isset($_POST['p_id'])){

    if ($stmt = mysqli_prepare($conn, "delete from cart where p_id=?")) {

        /* bind parameters for markers */
        mysqli_stmt_bind_param($stmt, "i", $_POST['p_id']);

        mysqli_stmt_execute($stmt);

    }
}

如何在单击按钮时显示jquery确认对话框?当我单击删除按钮时,它可能会显示一个确认框,但它很快就会消失!我不知道怎么了我使用jQuery Dialogify库

jquery modal-dialog
1个回答
0
投票
<script>
$("#remove").click(function(){
if(confirm("Are you sure you want to delete this?")){
    $("#delete-button").attr("href", "query.php?ACTION=delete&ID='1'");
}
else{
    return false;
}
});

© www.soinside.com 2019 - 2024. All rights reserved.