jquery移动版的问题,功能不起作用

Problems with jquery mobile, functions not working

本文关键字:功能 不起作用 问题 移动 jquery      更新时间:2023-09-26

我需要一些关于jquery移动应用程序的帮助。

http://www.mandinker.com/proyects_vip_dev/app-llarjove/

  1. 在此链接中,您会找到一些框,单击名为"CALENDARIO"的框。
  2. 好的,一切正常,然后按脚下拉并转到"INICIO"。
  3. 再做第一步,转到"CALENDARIO",然后 tada,错误!

这是错误:

类型错误:日历不是函数
...".ui-page-active .calendario").size()){calendario();$( "#datepicker" ).日期选择...

以下是相关的源代码:

$(document).delegate('.ui-page-active', 'pageshow', function () {
    if($(".ui-page-active .calendario").size()){
       calendario();
       $( "#datepicker" ).datepicker();
    }   
});
function makecalendar(){    
    $( "#datepicker" ).datepicker();
}
function calendario(){
    makecalendar();
    $.ajax({
        type: "POST",
        url: "http://llarjove.softonthecloud.net/calendar",
        data: {},
        error: function(){},
        success: function(data) {
            calendario=data;
            $(".calendario ul.ui-listview").html("");
            $("td").attr("class","ui-datepicker-unselectable");
            noticias=data.news;
            $.each(noticias,function(key,value){               
                tmp=value.fecha.split(" ");
                tmp=tmp[0].split("-");                               
                $("td[data-month="+(parseInt(tmp[1])-1)+"][data-year="+tmp[0]+"] > a").filter(function(){ 
            tmp[2]=tmp[2].replace(/^0+/, "");                       
        if($(this).text()==parseInt(tmp[2])){                       
            return $(this).text()==parseInt(tmp[2]);
        };    
        }).css({"background":"#00cae8","color":"white"}).attr("href","./calenItem.html?fecha='"+value.fecha+"'").on("click",function(){window.location.href = "./calenItem.html?fecha='"+encodeURIComponent(value.fecha)+"'";});
            });
        },
        dataType: "json",
        async: false
    });
    setInterval(function(){
        $(".ui-datepicker-calendar").height($(window).height()-$(".ui-header").height()-120);
    },300);
}

知道吗?

据我所知,您的 POST 请求仅在您第一次单击"CALENDARIO"时执行。我建议你调查2种可能性:

  1. 事件处理程序未触发,这通常发生在动态创建的内容上。要修复它,请将事件侦听器添加到父级。

  2. 确保在创建动态内容时要替换,而不是使用相同的 ID 进行复制,因为事件处理程序只会在 HTML 树中找到的第一个 ID 上触发

更新:我仔细看了你的代码,我会指出 2 件我认为奇怪并给你带来麻烦的事情。

我建议你从$(document).delegate()中删除

//I think this condition is always true on return or refresh and kills your flow
$( '.ui-page' ).not( '.ui-page-active' ).remove();

if (recarga) {
    location.reload();
    recarga=false;
};

$(document).ready()后也移动$(document).delegate()函数