Home >Web Front-end >JS Tutorial >Solution to invalid jQuery delegate event monitoring

Solution to invalid jQuery delegate event monitoring

黄舟
黄舟Original
2017-06-26 10:09:292222browse

During the development of WeChat, I found a solution to the eventno response of jQuery delegate binding.

The kids on the front end changed the original code of the following structure

<a href="ssss">
<p>sssss</p>
<p>dddddd</p>
</a>

to

<div data-href="ssss">
<p>ssssss</p>
<p>dddddd</p>
</div>

Because it involves some asynchronous loading content, the following code is used to implement the a tag Function

$(document).delegate(&#39;[data-href]&#39;, &#39;click&#39;, function () {            
if ($(this).data(&#39;href&#39;)) {
                location.href = $(this).data(&#39;href&#39;);
            }
        });

does not cause any problems on the PC browser, but when opened by the browser that comes with the iPhone 6, it directly failed.

Finally found the solution on stackoverflow, now recorded as follows:

On iOS there is no event bubbling without a cursor style. So in your CSS you need to add cursor: pointer; to the element.

Add CSS content

*[data-href]{cursor: pointer;
}

The above is the detailed content of Solution to invalid jQuery delegate event monitoring. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn