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

发布于 2024-12-09 09:52:47 字数 280 浏览 0 评论 0 原文

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

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

我对 .cancel 特别感兴趣,因为整个 jquery 代码块(此处不包括)都用于验证页面,并且我'如果用户单击取消按钮,我会尝试阻止验证。我猜上面的代码行是说单击的提交按钮不是取消按钮,然后继续。

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

Can someone help me understand this line of jquery code?:

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

I'm particularly interested in .cancel, since the whole chunk of jquery code (not included here) is being used to validate a page and I'm trying to prevent the validation if the user clicks on the cancel button. I'm guessing the above line of code is saying it the submit button clicked is NOT the cancel button, then continue.

But I don't know how to designate a button as cancel.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

失眠症患者 2024-12-16 09:52:47

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

  1. :输入
  2. 具有类型 = 提交,
  3. 没有 cancel

,或者

  1. 是一个按钮

Basically it is looking for elements located within this that has the following requirements

  1. is an input
  2. has type = submit
  3. does not have a class of cancel

OR

  1. is a button
任谁 2024-12-16 09:52:47

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

$(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
  );

Good answers here. Perhaps this annotated version adds some value.

$(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
  );
你与昨日 2024-12-16 09:52:47

他们应用一个名为cancel的CSS类来基本上象征取消按钮(然后检查它是一个没有这个类的按钮)

虽然我不知道你可以使用星号(*)在CSS类名中。

没关系,是你试图在代码块中加粗代码

我也很好奇为什么他们在想要取消时将取消按钮设置为提交类型无论如何。 (似乎 更合适)。

They're applying a CSS class named cancel to symbolize the cancel button basically (then checking it's a button with out this class)

Though I was un-aware you can use an asterisk (*) in a CSS class name.

Nevermind, it was you trying to bold code within a code block

I'm also curious why they make the cancel button of type submit when they want it to cancel anyways. (Seems like <input type="button" ... /> would be a better fit).

诺曦 2024-12-16 09:52:47

.cancel 是一个类选择器。具体来说,它正在查找 type 属性设置为 submit 但没有 cancel 类的 input 元素。它还查找带有 tagName button 的元素。

您可以像这样“指定一个按钮为取消”:

<input type='submit' class='cancel' />

.cancel is a class selector. Specifically it is looking for input elements with the type attribute set to submit, but don't have the cancel class. It also looks for elements with the tagName button.

You can "designate a button as cancel" like this:

<input type='submit' class='cancel' />
你是年少的欢喜 2024-12-16 09:52:47

基本上它是选择器说
给我提交按钮而不取消类和按钮并应用单击处理程序。
尝试查找以下选择器

标签
。班级
:不是

basically it is selector which says
give me submit buttons without cancel class and buttons and apply click handler.
try to look up the following selectors

tag
.class
:not

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文