When you work with each loop in jquery, the out-of-loop JS will still execute

Source: Internet
Author: User

Today in the project bug, I found a problem, I get a div in all input, and value, judge a condition, but the outside of the loop JS can still be executed.

   $ (". Tab-reg-next input"). each (function() {            if ($ (). attr ("id") = = 1) {                return  ;            }        });

Very strange, generally return will terminate JS, but today is not expected to be, jquery in each loop, return is not good, because the return in each and the outside of the function is not related, but only a single loop, so change to the following way, You can do it.

var true ;        $ (". Tab-reg-next input"). each (function() {            if ($ (). attr ("id") = = 1 ) {                false;                 return false ;            }        });         if (! result) {            $.fd.msg.notice ("Picture is too big, over 5MB")            ; return         }

When you work with each loop in jquery, the out-of-loop JS will still execute

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.