jQuery的event.preventDefault()不工作在Firefox(包括JSFiddle) [英] jQuery event.preventDefault() not working in Firefox (JSFiddle included)

查看:127
本文介绍了jQuery的event.preventDefault()不工作在Firefox(包括JSFiddle)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这种情况下,这与其他一些类似的重复,但我想在这种情况下正确使用 event.preventDefault()

b
$ b

下面是一个JSFiddle,你可以看到代码: http:// jsfiddle。 net / SeEw2 / 2 /

基本上,点击Submit按钮。



在Chrome浏览器中:没有任何反应 - 正确的回应。



在Firefox中:页面重新加载,哦!
$ b

那么为什么页面在Firefox中重新加载而不是Chrome呢?我已经Firebugging它,并没有出现错误...

解决方案

变量事件

在您的代码中
没有被初始化。

http://jsfiddle.net/SeEw2/4/

摘录:

<$点击(函数(事件){

//停止搜索输入重新加载页面,阻止其默认操作
event.preventDefault();


This is a kind of similar duplicate to some others here, but I think I'm using event.preventDefault() correctly in this case.

Here's a JSFiddle you can see the code with: http://jsfiddle.net/SeEw2/2/

Basically, click the Submit button.

In Chrome: Nothing happens - correct response.

In Firefox: Page reloads, oh noes!

So why is the page reloading in Firefox and not Chrome? I've been Firebugging it and no errors come up in either...

解决方案

The variable event in your code is not initialized.

http://jsfiddle.net/SeEw2/4/

extract :

 $('#ajaxsearch').click(function(event) {

        // Stop the Search input reloading the page by preventing its default action
        event.preventDefault();

这篇关于jQuery的event.preventDefault()不工作在Firefox(包括JSFiddle)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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