iPhone网络电话和电子邮件链接

时间:2011-09-18 18:42:54

标签: jquery iphone html touch

我有一个iPhone应用程序,我有很多链接,允许用户打电话或发电子邮件。

<a href="tel:12345678912">Call Us</a>
<a href="mailto:support@help.com">Email Us</a>

因为我使用jQuery预测每个<a>的默认值。

   var after = function(e, sender, action) {
       if (href.indexOf("tel:") === 0 || href.indexOf("mailto:") === 0) {
          return true;
       }

       // more of my code
   };

   if (window.Touch) {
        $("a").bind("touchstart", function(e1) {
            e1.preventDefault();

            var that = $(this);
            var moved = false;

            that.bind("touchmove", function(e2) {
                moved = true;
            });

            that.bind("touchend", function(e3) {
                that.unbind("touchmove");
                that.unbind("touchend");

                if (!moved) {
                    after(e3, this, "touchend");
                    return false;
                }
            });
        });
    }
    else {
        $("a").live("click", function(e) {
            e.preventDefault();
            after(e, this, "click");
        });
    }

不应该有用吗?

1 个答案:

答案 0 :(得分:1)

preventDefault表示您正在阻止链接执行。

从您的代码中看起来您正在停止点击链接,以便您可以使用更好的触摸事件。因此,您需要在成功时加载页面。

不是100%确定代码的工作方式,但看起来if (!moved) {就是点击链接并希望页面发生变化。所以只需添加window.location = this.href

相关问题