简体   繁体   English

jQuery-div onclick-在iPhone中不起作用

[英]jquery - div onclick - not working in iPhone

i tried different ways. 我尝试了不同的方法。
I need onclick for a div with jquery in my mobile site. 我需要在我的移动网站上使用jquery的div的onclick。 On clicking on the div it will send an ajax call. 在div上单击时,它将发送一个ajax调用。

$(document).ready(function() {
... ...... 

$('body').on('click','.selectableCard', function() { $('body')。on('click','。selectableCard',function(){

    $.ajax({
                url : URL}).done(
                function(data) {    .....    ....   });
        });
...
....
        });

This is working fine in desktop browsers and in android emulator. 这在台式机浏览器和android模拟器中运行良好。 But not working in iPode4 . 但不能在iPode4中使用

Div DIV

<div class="resultsMainContainer selectableCard  ">

style 样式

.selectableCard {
    pointer-events: auto !important;
}
.resultsMainContainer {
    background-color: #FFFFFF;
    border: 1px solid #D6D6D6;
    box-shadow: 3px 3px 5px 1px #CCCCCC;
    display: inline-block;
    margin-bottom: 15px;
    padding-bottom: 10px;
    padding-left: 10px;
    padding-top: 10px;
    width: 98%;
}

I tried as: 我尝试为:

$('.selectableCard').click(
        function(){....

But it's not working in desktop itself. 但是它不能在台式机上运行。 !

Any idea would be appreciated :) 任何想法将不胜感激:)

Here is an updated jsFiddle: http://jsfiddle.net/smilyface/y7DX5/1/ 这是更新的jsFiddle: http : //jsfiddle.net/smilyface/y7DX5/1/

Will work fine in desktop , but not working in iPod 在台式机上可以正常工作,但在iPod上不能正常工作

On iphone you must use touchevent for exemple: 在iPhone上,您必须使用touchevent作为touchevent

$('.selectableCard').on('click touchstart',function(){
//your code
});

Got it working. 得到它的工作。

I just put the entire onclick function (onclick selectableCard) inside the ajax. 我只是将整个onclick函数(onclick selectableCard)放在ajax中。 So that it will run each time when the ajax loads. 这样它将在每次加载ajax时运行。 Thus it can get the class/div specified inside the jQuery. 因此,它可以获取jQuery内部指定的class / div。

$.ajax({
            url : URL
            }).done(
            function(data) {

                container.html(data); //innerHTML part
                $('.selectableCard').click(function(){..call div came through above innerHTML..});
});

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

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