问题
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