Javascript 类型错误:e[h] 不是函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11979852/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 07:55:07  来源:igfitidea点击:

TypeError: e[h] is not a function

javascriptjquery

提问by Fede E.

I've been using jquery 1.6 with no problem. Today I switched to jquery 1.8 and suddenly I am getting this error when trying to submit a form:

我一直在使用 jquery 1.6 没有问题。今天我切换到 jquery 1.8,在尝试提交表单时突然出现此错误:

TypeError: e[h] is not a function.

Form:

形式:

<form method="post" action="login?login" name="login" id="login">
<input class="input" type="text" name="user_mail" id="user_mail" autocomplete="on" />
<input class="input" type="password" name="password" id="password" autocomplete="off" />
<a class="green_button" href="javascript:void(0)" id="login_button">Login</a>
<input type="submit" name="login" id="submit" style="visibility:hidden" />
</form>
<script language="javascript">
$("#login_button").click(function(){
    $("#login").submit();   
});
</script>

Am I missing something?

我错过了什么吗?

Thanks!

谢谢!

回答by xdazz

Remove the line below.

删除下面的行。

<input type="submit" name="login" id="submit" style="visibility:hidden" />

Update:

更新:

Or if you have to use the submit input, then you need to change the id submitto something else. The reason is that if you have an input element with idof submit, it will set a submitproperty to the form with the HTMLInputElement. So you could not call the .submitmethod on the HTMLFormElement.

或者,如果您必须使用提交输入,那么您需要将 id 更改submit为其他内容。原因是,如果您有一个带有idof的输入元素submit,它将submit为带有 HTMLInputElement 的表单设置一个属性。所以你不能.submit在 HTMLFormElement 上调用该方法。

回答by Aman Aujla

I waster 3 hours trying to fix the same issue, I was using the name='submit' for my submit button and was calling $("#form_name").submit(); in a function and was getting the error. Sometimes small things I overlook end up wasting lot of time.

我浪费了 3 个小时试图解决同样的问题,我在提交按钮上使用了 name='submit' 并调用了 $("#form_name").submit(); 在一个函数中并得到错误。有时我忽略的小事最终会浪费很多时间。

回答by alpera

i think it's because the line

我认为这是因为线路

<input type="submit" name="login" id="submit" style="visibility:hidden" />

can you remove it and retry?

你可以删除它并重试吗?

回答by Mausmee Rai

When we use a submit type element in a form, This element will be set as Submit property of the form. So one could not call the submit() function with other element of form.

当我们在表单中使用提交类型元素时,该元素将被设置为表单的 Submit 属性。所以不能用表单的其他元素调用 submit() 函数。

There are two ways to do this. first one is just remove the line as given in first reply.

有两种方法可以做到这一点。第一个只是删除第一个回复中给出的行。

Or Use $("#submit").trigger("click"); instead of $("#login").submit();. and it will submit the form on pressing enter key word too.

或者使用 $("#submit").trigger("click"); 而不是 $("#login").submit(); . 它也会在按下输入关键字提交表单。

回答by Matt Cavanagh

With jQuery 1.7 (possibly above too) if you have the nameproperty also called submitit will break.

使用 jQuery 1.7(也可能在上面),如果您name还调用submit了该属性,它将中断。

E.g.

例如

<input type="submit" name="submit" value="Upload">

<input type="submit" name="submit" value="Upload">

Will not work, however:

但是,不起作用:

<input type="submit" name="sendSubmit" value="Upload">

<input type="submit" name="sendSubmit" value="Upload">

Is fine.

很好。

回答by Hymanwanders

Your formand inputhave the same name attribute value, login.

您的forminput具有相同的名称属性值,login

Change the nameon the inputto something else, like submit. This should clear up your error.

name上的更改input为其他内容,例如submit。这应该会清除您的错误。