jQuery preventDefault在iOS 9上无法正常工作 [英] jQuery preventDefault not working correctly on iOS 9

查看:70
本文介绍了jQuery preventDefault在iOS 9上无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery在这样的固定标题中的搜索框中淡入淡出...

I am using jQuery to fade in a search box in a fixed header like this...

<script type="text/javascript">  
    jQuery(document).ready(function()
        {
            jQuery(".search_button").click(function()
                {
                    event.preventDefault();
                    jQuery(".h_search").fadeIn("fast");
                    jQuery( "#search" ).focus();
                }); 
   });
</script>

我正在使用preventDefault来阻止单击链接时页面跳至顶部,它在装有iOS 7的iPhone 4上可以正常工作,但在装有9的iPhone 4s和iPad mini上却无法正常工作,并且内容仍然跳动.

I am using preventDefault to stop the page jumping to the top when the link is clicked, it works correctly on an iPhone 4 with iOS 7 but on an iPhone 4s and iPad mini with 9 it doesnt work and the content still jumps.

有任何想法吗?

推荐答案

您需要将事件传递到回调中.

You need to pass the event into the callback.

<script type="text/javascript">
    jQuery(document).ready(function() {
        jQuery(".search_button").click(function(event) {
            event.preventDefault();
            jQuery(".h_search").fadeIn("fast");
            jQuery("#search").focus();
        });
    });
</script>

这篇关于jQuery preventDefault在iOS 9上无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆