【问题标题】:prevent multiple call in appframework touchevents防止 appframework touchevents 中的多次调用
【发布时间】:2014-04-22 14:12:47
【问题描述】:

我正在使用英特尔 Appframework 来创建 Android 应用程序。现在我正在尝试绑定 touchevent,但我发现这会产生冗余的多个 ajax 调用!

这是我的脚本:

$(document).on("doubleTap", ".chatOp a[rel]", function(){
        var nomeSuo = $(this).attr('rel');
        $.post('http://www.mimanchitu.it/appf/include/chat_con.asp', {M_FROM:localStorage.getItem("nameStorage"),M_TO:nomeSuo}, 
    function(oldChat){
        $("#showChat").empty();
        $("#showChat").html(oldChat);
        return $.ui.loadContent("#chat_con")
        });
    })


$(document).on("longTap", ".chatOp a[rel]", function(){
        var nomeSuo = $(this).attr('rel');
        var nomeTuo = localStorage.getItem("nameStorage");
        alert("vuoi eliminare?");
        $.post('http://www.mimanchitu.it/appf/include/chat_delAll.asp', {from:nomeSuo,to:nomeTuo}, function(){
            $("#"+nomeSuo).remove();
            });
    })

我用它来为双击或长按情况绑定不同的事件!但在所有两种情况下都进行多个 ajax 调用!

为了防止在其他情况下多次调用,我使用 onclick: 在一个元素中......但是对于触摸我必须怎么做?!

【问题讨论】:

    标签: javascript android ajax appframework


    【解决方案1】:

    您是否尝试过将preventDefault() 作为匿名函数中的第一条语句?您需要将event 作为参数传递:

    $(document).on("longTap", ".chatOp a[rel]", function(event){
       event.preventDefault();
       ...
    

    【讨论】:

    • 我会尝试但永远不会改变。我个人的解决方案是指定一个div:例如:$('#mydiv').on("longTap", ".chatOp a [rel]", ecc...
    猜你喜欢
    • 1970-01-01
    • 2022-10-14
    • 1970-01-01
    • 2019-07-13
    • 2020-02-23
    • 2018-04-12
    • 1970-01-01
    • 2021-10-13
    • 1970-01-01
    相关资源
    最近更新 更多