Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery确认对话框什么也不做_Jquery_Html - Fatal编程技术网

jquery确认对话框什么也不做

jquery确认对话框什么也不做,jquery,html,Jquery,Html,我试图使用jquery显示确认对话框,但当我单击链接时,什么也没有发生。这是我的代码,如果我将警报放在就绪功能中,我可以看到警报,但在单击中看不到警报: $(document).ready(function() { $("#mydialog").dialog({ autoOpen: false, modal: true }); }); $(".myconfirmLink").click(function(e) { e.preventDefa

我试图使用jquery显示确认对话框,但当我单击链接时,什么也没有发生。这是我的代码,如果我将警报放在就绪功能中,我可以看到警报,但在单击中看不到警报:

$(document).ready(function() {
    $("#mydialog").dialog({
        autoOpen: false,
        modal: true
    });
});
$(".myconfirmLink").click(function(e) {
    e.preventDefault();
    var targetUrl = $(this).attr("href");
    $("#mydialog").dialog({
        buttons: {
            "Yes": function() {
                $(this).dialog("close"), window.location.href = targetUrl;
            },
            "No": function() {
                $(this).dialog("close");
            }
        }
    });
    $("#mydialog").dialog("open");
});​
在链接上,我这样称呼它:

<div class="topToolbar">
                    <span> <a href="/Logout.aspx" class="myconfirmLink">Log Out</a></span>
                    <div id="mydialog" title="Confirmation Required">
                <p> Are you sure you want to request a new pack?</p>
            </div>

您确定要申请新的软件包吗


在document.ready函数中移动您的单击绑定

$(document).ready(function() {
    $("#mydialog").dialog({
        autoOpen: false,
        modal: true
    });
    $(".myconfirmLink").click(function(e) {
        e.preventDefault();
        var targetUrl = $(this).attr("href");
        $("#mydialog").dialog({
            buttons: {
                "Yes": function() {
                    $(this).dialog("close"), window.location.href = targetUrl;
                },
                "No": function() {
                    $(this).dialog("close");
                }
            }
        });

        $("#mydialog").dialog("open");
    });
});​
它很可能是试图在元素存在于dom中之前将其绑定到该元素。这里很好用


在document.ready函数中移动单击绑定

$(document).ready(function() {
    $("#mydialog").dialog({
        autoOpen: false,
        modal: true
    });
    $(".myconfirmLink").click(function(e) {
        e.preventDefault();
        var targetUrl = $(this).attr("href");
        $("#mydialog").dialog({
            buttons: {
                "Yes": function() {
                    $(this).dialog("close"), window.location.href = targetUrl;
                },
                "No": function() {
                    $(this).dialog("close");
                }
            }
        });

        $("#mydialog").dialog("open");
    });
});​
它很可能是试图在元素存在于dom中之前将其绑定到该元素。这里很好用


看起来您在
ready
函数之外设置单击处理程序。
$(“.myconfirmLink”)。单击(函数(e){…})代码是在jQuery准备就绪之前运行的。

看起来您在
ready
函数之外设置了单击处理程序。
$(“.myconfirmLink”)。单击(函数(e){…})代码是在jQuery准备就绪之前运行的。

他们的代码没有问题。只需将确认链接单击处理程序代码移动到document.ready函数中即可。它们的代码没有问题。只需将确认链接单击处理程序代码移动到document.ready函数中,即可使其正常工作