jQuery: Any better way to write this? Multiple each() loops -


  var वर्तमानतमतम = 0; यदि ($ जम्मू ("। प्रत्येक लाइटडेल") मौजूद है ()) {$ j (this)। बच्चे ()। ("परिणाम परिणाम")। प्रत्येक (फ़ंक्शन (i) {if ($ j (this)। () & Gt; वर्तमानतमतम) {currentTallest = $ j (यह) .height ();}}); $ J (this)। बच्चे ()। ("परिणाम परिणाम")। प्रत्येक (फ़ंक्शन (i) {if (! $ J.support.minHeight) {$ j (this) .css ({'height': currentTallest + 5});} $ j (this) .css ({'min-height': वर्तमानटेलास्ट});}); }   

अपडेट: सभी रचनात्मक टिप्पणियों को ध्यान में लेने के बाद, मैं निम्नलिखित के साथ आया हूं जो वांछित के रूप में काम करता है:

  $ j Fn.equalHeights = function (px) {$ j (this) .each (function () {var currentTallest = 0; var परिणाम; यदि ($ j ("। प्रत्येक लेतेडियल")। लंबाई) {परिणाम = $ j (" परिणाम, पता "," .eachLateDeal ");} अन्य {परिणाम = $ जे (यह)। बच्चे ();} $ जे.ईच (परिणाम, कार्य () (यदि ($ j (यह)। हल्का () & gt; वर्तमान न्यूनतम ) {CurrentTallest = $ j (this) .height ();}}); var cssProp = {}; अगर (! $ J.support.minHeight) {cssProp ["height"] = वर्तमानतम + 5;} और {cssProp ["न्यूनतम ऊंचाई"] = वर्तमानतमतम;} results.css (cssProp);});   

};

धन्यवाद!

< P> आप देख रहे हैं कि आप के लिए अधिकतम मूल्य प्राप्त करने के लिए जावाकैप मैथ ऑब्जेक्ट का इस्तेमाल कर सकते हैं जिसका मतलब है कि आप अपनी सभी कार्यक्षमता को एक लूप में लपेट सकते हैं:
  $ (document) .ready (function () { Array.max = function (array) {return Math.max.apply (Math, array);}; if ($ j ("। प्रत्येक लाइटडियल")। लंबाई) {var heights = new Array (); var परिणाम सूची = $ j (यह)। बच्चे ()। ("परिणाम परिणाम") खोज परिणाम (सूची।) (समारोह () {हाइट्स। पश ($ जे (यह)। हाइट ());}); var max = Array.max (हाइट्स ); Var propertyName = 'min-height'; अगर (! $। Support.minHeight) {max = अधिकतम + 5; propertyName = 'height';} resultLists.css (गुणनाम, अधिकतम);}});   



Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -