在Safari中防止默认 [英] preventDefault in Safari

查看:79
本文介绍了在Safari中防止默认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含代码的文本框;

I have a textbox which has the code;

<input type="text" maxlength="5" size="2" value="1" id="paging_textbox">

此页面上没有封面表格标签..

Now there is no encloding form tag on this page..

当用户在此文本框中键入并按Enter键时,此页面上的表格会更新(通过AJAX调用)

When user types in this textbox and presses Enter, the table on this page is updated (via AJAX call)

在Safari中,行为略有不同在某种意义上它是不同的,即使它正确地更新表,它会重新加载页面(认为它提交表单,但不确定如何没有表单标记)并将文本框值重置为1

In Safari, the behavior is slightly different in the sense that even though it updates the table correctly, it kind of reloads the page (think it submits the form, but not sure how as there is no form tag) and resets the textbox value back to "1"

如何防止在Safari中发生这种情况?

How do I prevent this from happening in Safari ?

请帮助我。谢谢。

推荐答案

为了确保,使用终止你的回调函数返回false
这应该可以解决问题。

Just to be sure, terminate your callback function with a return false. That should do the trick.

 function(e) {
     e.preventDefault();
     // some awesome code
     return false;
 }

哦,还有一件事:将来,要避免这种随机行为。 。尊重标准,使用表格:)

Oh, and another thing: in the future, to avoid such random behavior.. respect the standards, use a form :)

这篇关于在Safari中防止默认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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