Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.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 Mobile changepage使父函数运行两次_Jquery_Html_Jquery Mobile_Web - Fatal编程技术网

jQuery Mobile changepage使父函数运行两次

jQuery Mobile changepage使父函数运行两次,jquery,html,jquery-mobile,web,Jquery,Html,Jquery Mobile,Web,大家好,我的jQuery移动脚本似乎有问题 <script> $(document).bind('pageinit', function() { var count=0; var pages = ["#home","#rich","#dan"]; $('.master').click(function() { count=count+1; $.mobile.change

大家好,我的jQuery移动脚本似乎有问题

<script>
$(document).bind('pageinit', function()
    {
        var count=0;
        var pages = ["#home","#rich","#dan"];
        $('.master').click(function() 
        {
        count=count+1;

            $.mobile.changePage($(pages[count]));

            console.log(count);         

        });

    });
</script>

$(document).bind('pageinit',function()
{
var计数=0;
var pages=[“#home”、“#rich”、“#dan”];
$('.master')。单击(函数()
{
计数=计数+1;
$.mobile.changePage($(页面[计数]);
控制台日志(计数);
});
});
所以,第一次点击就会发生什么,它会起作用。计数增加到1,页面变为#rich。第二次单击,计数变为2。页面快速闪烁至#丹,然后向右闪烁至#里奇,计数变为1。如果我再次单击,我会收到一个错误消息

b、 数据(“页面”)未定义


不知道为什么。有什么帮助吗?

正如Huangism所建议的,很可能是重置了您的计数器。尝试使用$(document).ready()或其他仅触发一次的事件设置单击事件

我不太熟悉jquery mobile,但pageinit是否在每次加载新页面时都运行?所以,当页面处于“rich from home”状态时,pageinit是否运行?我切换到document.ready,并修复了它。我编辑了我的评论,加入了我的代码,使之倒退,这给了我同样的问题。