简体   繁体   English

iPhone中的jQuery

[英]jQuery in iPhone

Very simple jQuery doesn't work in Safari for iPhone and iPod touch. 非常简单的jQuery在iPhone和iPod touch的Safari中不起作用。 I make a simplified case: 我做了一个简化的案例:

$(function(){
  $("#boto").click(function() {
    $("#boto2").fadeOut("slow");
  });
})

http://jsfiddle.net/vWfNj/ http://jsfiddle.net/vWfNj/

http://www.mig-marketing.com/proves2/3.html http://www.mig-marketing.com/proves2/3.html

It works in computers, it works in iPad but not in my iPod touch. 它适用于计算机,适用于iPad,但不适用于iPod touch。 I'm so surprised, I don't understand. 我很惊讶,我不明白。 Does jQuery needs anything special for Safari in iPhone? jQuery是否需要iPhone的Safari特殊功能?

The iphone doesnt have a click event, it has a touch event try this. iPhone没有点击事件,但有触摸事件,请尝试此操作。

$('.class').bind('touchend', function () {
//Code
});

Edit : No idea what your comment means but here.... 编辑:不知道您的评论意味着什么,但是在这里...。

$(function(){
  $("#boto").bind('touchend', function () {
    $("#boto2").fadeOut("slow");
  });
})

Be aware that on iOS 5, your #boto has to be inserted into the DOM before you attach event handlers to it. 请注意,在iOS 5上, #boto插入DOM中, 然后才能将事件处理程序附加到该DOM。 I had a similar problem a few days ago : jQuery events on iOS 5 前几天我遇到了类似的问题: iOS 5上的jQuery事件

尝试使用.touch代替.click当你点击任何触摸支持设备的触摸事件。

I found out that the only problem is with the hosted jQuery library from Google. 我发现唯一的问题是来自Google的托管jQuery库。 I don't understand why my iPod touch can download the page but not the jQuery library. 我不明白为什么我的iPod touch可以下载页面而不下载jQuery库。 I don't know if it is a problem in all iPhones and iPod touch... 我不知道是否所有iPhone和iPod touch都有问题...

Anyway If I download the jQuery library, it works fine. 无论如何,如果我下载了jQuery库,它就可以正常工作。 And of course the click function works in the iPhone. 当然,单击功能也可以在iPhone中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM