0

以下的jQuery工作在大多数桌面浏览器罚款,但没有对Android和iPhone浏览器:为什么这个jquery函数不能在iPhone OS上工作?

$('#submit_event').live('click', function() { 

    if ($("#event_name").attr("value") != "" && $("#event_details").attr("value") != ""){ 
     sendEvent($("#event_name").attr("value"), $("#event_details").attr("value")); 
     $('#response_container').append("<div class='event_title'>"+$("#event_name").attr("value")+"</div><div class='event_details'>"+$("#event_details").attr("value")+"<div class='comment'>Comment</div><textarea class='comment_area'></textarea><div id='post_comment'>Post</div></div>"); 
    } 
}); 

的#submit_event仅仅是ID的DIV。点击后,它会在桌面浏览器上运行该功能,但不会运行android或iphone。

问候,

泰勒

+1

什么是'sendEvent'方法? – 2011-05-05 05:37:57

回答

0

你可以尝试更有效的代码:

$('#submit_event').live('click', function() { 

    var eName = $("#event_name").attr('value'); 
    var eDetails = $("#event_details").attr('value'); 

    if (eName && eDetails) { 
     sendEvent(eName, eDetails); 
     $('#response_container').append("<div class='event_title'>" + 
      eName + 
      "</div><div class='event_details'>" + 
      eDetails + 
      "..." 
     ); 
    } 
}); 
+0

似乎没有这样的伎俩:/ – TaylorMac 2011-05-05 17:39:40

+0

也许别的东西只是在这个函数 – TaylorMac 2011-05-05 17:39:51

0

好吧,我发现我的答案,

这只是在移动Safari浏览器的错误。

所有你需要做的就是添加的onclick =“”到你的肝功能绑定到任何元素,它会工作。

0

是.live事件不会像TD元素工作。它会与像锚标签,按钮等HTML元素的工作,所以,如果你想使用jQuery的.live事件,你需要首先添加的onclick应用Click事件=“”使用TD元素jQuery的.attr方法,然后属性应用。现场活动将事件与您的td元素绑定。欲了解更多详情,请访问下面博客

http://skillfulness.blogspot.com/2010/11/workaround-for-jquery-live-event.html

+0

万一别人简单的修复错误不是在未来有这个问题。只需添加一些简单的CSS即可解决问题。

Click Me
Anthem127 2012-11-26 14:59:52

0

如果您正在使用jQuery Mobile的太多,你可能会想尝试

$('#submit_event').live('tap', function() {} 
相关问题