jQuery preventDefault not working correctly on iOS 9

回眸只為那壹抹淺笑 提交于 2020-01-07 03:01:48

问题


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>

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.

Anyone any ideas?


回答1:


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>


来源:https://stackoverflow.com/questions/34322597/jquery-preventdefault-not-working-correctly-on-ios-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!