In the project itself, when writing a very simple form validation, you need to traverse all textarea and judge. Because of jquery, the first reaction is to use each function traversal, when traversing to an empty textarea, pop-up hints and interrupt the operation of JS. At first I wrote this:
1 Input.each (function () { 2 if ($ (this ). val () = = null ) 3 { 4 alert ("Test"
);
5
false
;
6
7 // other code 8 });
After running, the popup will appear, but then the code is run, and all the textarea are traversed.
After looking at the source code of each () function (in fact, not thoroughly), the first thought is to use a for loop instead. The code is simply not written. Another method is to throw an exception. Examples are as follows:
1 Try2 {3Input.each (function(){4 if(!empty_validation ($ ( This)))5 Throw false;6 });7 } 8 Catch(e)9 {Ten return false; One}
Each function in jquery is a small note