$(this).find('input [type ="submit"]:not(.cancel),button').click(function() - 这是什么?

mer*_*erk 6 jquery jquery-selectors

有人可以帮我理解这行jquery代码吗?:

$(this).find('input[type="submit"]:not(.cancel), button').click(function ()
Run Code Online (Sandbox Code Playgroud)

我特别感兴趣.cancel,因为整个jquery代码块(这里没有包含)用于验证页面,我试图阻止验证,如果用户点击取消按钮.我猜测上面的代码行说它点击的提交按钮不是取消按钮,然后继续.

但我不知道如何将按钮指定为取消.

Joh*_*ock 12

基本上它正在寻找this具有以下要求的元素

  1. 是一个输入
  2. 有type = submit
  3. 没有一类 cancel

要么

  1. 是一个按钮


Ken*_*ler 9

这里的答案很好.也许这个带注释的版本增加了一些价值.

$(this)                   // within this jQuery object
  .find('                 // find all elements
    input[type="submit"]  // that are input tags of type "submit"
    :not(.cancel)         // and do not have the class "cancel"
    ,                     // or
    button                // are button elements
  ')
  .click(                 // and for each of these, to their click event
    function (){}         // bind this function
  );
Run Code Online (Sandbox Code Playgroud)