甜蜜警报2.重置以防止默认设置

时间:2018-10-29 12:20:07

标签: php jquery

您好,我有一个href指向一个删除文件的文件(unlink.php)。 现在,我已经设置了甜蜜警报,以在单击unlink.php的链接时显示。这可行,但是当我在甜蜜警报中单击“确定”时,什么也没有发生。我需要一些在甜蜜警报框中单击“确定”时如何重置preventDefault函数。谢谢。

甜警报码:

val view = inflater.inflate(R.layout.util_description_fragment, container, false)
......
val popup = PopupMenu(wrapper, view)

4 个答案:

答案 0 :(得分:1)

希望这对您有帮助...

<script>
    $('#unlink').on('click', function(e) {
        e.preventDefault();
        swal({
            title: 'Är du säker?',
            text: "Denna bild kommer att raderas!",
            type: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Ja, radera denna bild!'
         }).then((result) => {
            if (result.value) {
                //Ajax call to delete file          
                [....] // ajax stuff 
                if(resp.status == 'success') {
                    swal(
                        'Raderade!',
                        'Bilden är nu raderad.',
                        'success'
                    )
                }
                else {
                    swal(
                        'Fel!',
                        'Misslyckades att radera bilden.',
                        'error'
                     )
                 }
            } 
         });
     )};
</script>

答案 1 :(得分:0)

这就是我现在拥有的,它删除了图像,但我再也看不到甜美的aleret盒子。

            <script>
        $('#unlink').on('click', function(e) {
            e.preventDefault();

                        swal({
                        title: 'Är du säker?',
                        text: "Denna bild kommer att raderas!",
                        type: 'Varning',
                        showCancelButton: true,
                        confirmButtonColor: '#3085d6',
                        cancelButtonColor: '#d33',
                        confirmButtonText: 'Ja, radera denna bild!'
                        }).then((result) => {
                        if (result.value) {
                            $.ajax({
                                url: 'unlink.php'
                            })
                        if(resp.status == 'success') {
                            swal(
                                'Raderade!',
                                'Bilden är nu raderad.',
                                'success'
                            )
                        }
                        else {
                            swal(
                                'Fel!',
                                'Misslyckades att radera bilden.',
                                'error'
                            )
                        }
                    } 
                });
            )};
        </script>

答案 2 :(得分:0)

好,现在我可以使用此代码了,问题是,即使我单击“取消”,图像仍会被删除。

<script>
                $('.unlink a').on('click', function(e) {
                e.preventDefault(); // Prevent the href from redirecting directly

                swal({
                title: 'Radera!',
                text: "Är du säker?",
                type: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Ja, radera denna bild!',
                cancelButtonText: 'Nej, radera ine denna bild!',
                closeOnCancel: true

                }).then(function (e) {
                if (true) {
                    window.location = "unlink.php?filename=<? echo $file?>";
                    }
                    })
                })                  
            </script>

答案 3 :(得分:0)

我现在进来了

<script src="https://cdn.jsdelivr.net/npm/sweetalert2@7.28.10/dist/sweetalert2.js"></script>
           <script>
                $('.unlink > a:nth-child(2)').on('click', function(e) {
                        e.preventDefault();

                        swal({
                        title: 'Vill du radera denna bild?<br><? echo $file?>',
                        text: "Om du klicka på ja, så kommer denna bild att raderas!!!",
                        type: 'warning',
                        showCancelButton: true,
                        confirmButtonColor: '#d33',
                        cancelButtonColor: '#3085d6',
                        confirmButtonText: 'Ja, Radera!',
                        cancelButtonText: 'Nej, Avbryt!',
                        }).then((result) => {
                    if (result.value) {
                        window.location.href = "unlink.php?filename=<? echo $file?>";
                    } else if (
                        // Read more about handling dismissals
                        result.dismiss === swal.DismissReason.cancel
                    ) {
                        // If cancel do nothing
                    }
                    })
                    })
            </script>
相关问题