对话框与其他脚本冲突

时间:2014-05-13 08:43:34

标签: javascript jquery

我在将Jquery UI对话框集成到其他脚本中时遇到问题。我想要做的是检测用户不活动,并在一定的不活动时间后显示一个对话框,要求继续或关闭会话。我的代码:

    <link href="css/smoothness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
    <script src="js/jquery-1.10.2.js"></script>
    <script src="js/jquery-ui-1.10.4.custom.js"></script>

</head>
<body>

<div id="dialog-confirm" title="Session expirée">
<p><span style="float:left; margin:0 0px 0px 0;"></span>Session expire, continue ?</p>
</div>

<script>

    var theTime;

    document.onmousemove=stockTime;
    function stockTime() {
        currentTime=new Date();
        theTime=currentTime.getTime();
    }
    function verifTime() {
        currentTime=new Date();
        var timeNow=currentTime.getTime();
        if (timeNow-theTime>10000) {

            $( "#dialog-confirm" ).dialog({
                resizable: false,
                height:190,
                modal: true,
                buttons: {
                "Continue": function() {
                $( this ).dialog( "close" );
                },
                "End": function() {
                $( this ).dialog( "close" );
                }
                }
            });      
        }
    }
    window.setInterval("verifTime()",2500);

</script>

我的控制台向我发送了这条消息:&#34; TypeError:$(...)。dialog不是函数&#34;。我不知道问题出在哪里......

感谢您的帮助,抱歉我的英语不好!

2 个答案:

答案 0 :(得分:1)

检查所有文件是否按正确顺序加载

<link href="http://code.jquery.com/ui/1.9.2/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>

你剩下的代码工作正常。

Tested in JSBIN

答案 1 :(得分:0)

你在哪里加了jquery?如果你没有添加它,将它添加到你的脚本上面,如果你添加它,那么我认为你将它添加到你的脚本下面,在jquery之后移动你的脚本。并在执行此操作后,在dom加载后加载脚本

$(function(){
//Put your Script here
})
相关问题