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了。

  • 相关阅读:
    shipyard-----------docker容器的可视化管理
    dockerfile制作镜像
    docker容器ip地址的设定
    docker镜像文件的安装和容器的操作
    Docker网络模式
    docker整体了解
    spring的aop学习(1)
    SqlSessionFactory的创建过程
    spring+springMVC+Maven+mysql环境搭建
    dubbo入门示例
  • 原文地址:https://www.cnblogs.com/youxin/p/2948840.html
Copyright © 2011-2022 走看看