javascript - 无法弹出 jQuery 对话框

标签 javascript jquery

我试图在按下此处的“upvote”链接后弹出 jQuery 对话框:http://www.problemio.com

(我从这个例子开始工作,然后修改它,因为它对我不起作用:http://blog.nemikor.com/2009/04/08/basic-usage-of-the-jquery-ui-dialog/)

这是我目前无法使用的 jQuery 代码:)

<script type="text/javascript">
$(document).ready(function() 
{
   var $dialog = $('.dialog')
           .dialog({
               autoOpen: false,
               title: 'Basic Dialog'
           });   

    $('.vote_up').click(function() 
    {        
        problem_id = $(this).attr("data-problem_id");

        var dataString = 'problem_id='+ problem_id + '&vote=+';

        $.ajax({
                type: "POST",
                url: "/problems/vote.php",
                dataType: "json",
                data: dataString,
                success: function(data)
                {           
                    // ? :)
                    alert (data);   
                },
                error : function(data) 
                {
                    //alert("ajax error, json: " + data.responseText);
                    errorMessage = data.responseText;

                    if ( errorMessage == "not_logged_in" )
                    {
                        alert ("errr");

                        // Try to create the popup that asks user to log in.
                        //$(this).dialog();
                        //$(".dialog").dialog();
                        $dialog.dialog('open');
                        // prevent the default action, e.g., following a link
                        return false;
                    }
                    else
                    {
                        alert ("not");
                    }

                    //alert(JSON.stringify(data));
                }
            });


        //Return false to prevent page navigation
        return false;
    });

    $('.vote_down').click(function() 
    {
        alert("down");

        problem_id = $(this).attr("data-problem_id");

        var dataString = 'problem_id='+ problem_id + '&vote=-';        

        //Return false to prevent page navigation
        return false;
    });    
});
</script>

在这段代码之上,我有另一个 jQuery 函数,它也有一个 documentOnready 检查。那有关系吗?我应该使对话框代码全局化吗?如果是这样,我该怎么做?

无论如何,如何使用我现在的设置为我打开对话框?

谢谢!!

将我的 jQuery 导入更改为此:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.16/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" />

最佳答案

您需要包含 jQuery UI script在你的页面上。这就是包括 dialog plugin 的内容.

目前您只在 HTML 中引用 jQuery 1.6.4。

关于javascript - 无法弹出 jQuery 对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7675005/

相关文章:

javascript - 通过 OAuthSimple.js 发布到 Twitter

javascript - 如何更改 Flot 中 y 轴值的步进?

javascript - 弹出警报消息后,javascript 是否仍在运行?

javascript - azure 聊天机器人 v4 如何在 Internet Explorer 中工作?

javascript - 在函数范围内关闭 console.log

javascript - 复制检索到的 json 数据并以文本格式粘贴到文本编辑器中

jquery - 如何添加/插入 json data[0] 等到 jquery $ ('td' ).css?

javascript - 当您滚动更多时,JQuery 滚动事件会继续触发

javascript - 在 PHP 中从国家代码获取货币信息

jquery - 整个div的反射(reflect)