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

  • 相关阅读:
    jQuery事件
    jQuery选择器
    jQuery对象和语法
    jQuery简介
    残差的正态性检验——概率图和QQ-plot图
    https://oldpan.me/深度学习博客
    深度学习的内存消耗在哪里?
    图片缩放
    随机梯度下降批尺寸的影响
    利用PIL.ImageOps.invert实现二值图像黑白反转
  • 原文地址:https://www.cnblogs.com/youxin/p/2948840.html
Copyright © 2020-2023  润新知