开发者

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

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 开发者_如何学PythonI don't know how to designate a button as cancel.


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


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


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).


.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' />


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜