zoukankan      html  css  js  c++  java
  • jQuery .submit()没响应

    一个郁闷了好久的错误:

    <form method="get">
    <input type="text" name="search" id="search" />
    <input type="submit" value="submit" id="submit" />
    </form>

    $("#submit").submit(function(){
     alert("hello");

    return false;

    });

    问题是无论点击多次次,都不会运行.在官网找到了答案:

    .submit( )

    This method is a shortcut for .on('submit', handler) in the first variation, and .trigger('submit') in the third.

    The submit event is sent to an element when the user is attempting to submit a form. It can only be attached to <form>elements. Forms can be submitted either by clicking an explicit <input type="submit"><input type="image">, or<button type="submit">, or by pressing Enter when certain form elements have focus.

    Depending on the browser, the Enter key may only cause a form submission if the form has exactly one text field, or only when there is a submit button present. The interface should not rely on a particular behavior for this key unless the issue is forced by observing the keypress event for presses of the Enter key.

    官网已经说的很清楚了,这个.submit只能用于form元素,而不能用于submit,button等。

    改为$("form").submit 后就ok了。

  • 相关阅读:
    CF 986A Fair——多源bfs
    poj3539 Elevator——同余类bfs
    poj3463 Sightseeing——次短路计数
    poj2262 Goldbach's Conjecture——筛素数
    Kruskal算法
    Prim算法
    离散化
    最短路(hdu2544)
    最短路径问题
    Servlet
  • 原文地址:https://www.cnblogs.com/youxin/p/2948840.html
Copyright © 2011-2022 走看看