jquery - Get count and height of Html.ListBoxFor item -


का उपयोग करना

  • सी #
  • MVC 5 < li> उस्तरा 3

    मेरे पास एचटीएमएल। लिस्टबॉक्स है ...

      @ html.ListBoxFor (x = & gt; x.SunSelectedList, Model.sunList , नई {@class = "पात्र उपलब्ध लिस्टबॉक्स"})   

    मेरे पास jQuery के जावास्क्रिप्ट है ..

      @section scripts {& lt; script type = "text / जावास्क्रिप्ट "& gt; $ (फ़ंक्शन () {var ssList = $ ("# sunSelectedList"); // उपरोक्त चर वैध है और सभी आइटम शामिल हैं}); & Lt; / स्क्रिप्ट & gt; }   

    चर ssList के साथ, मैं कैसे विकल्पों की गिनती और प्रत्येक आइटम की क्लाइंट ऊंचाई कैसे प्राप्त करूं?

    विकल्पों की संख्या प्राप्त करने के लिए

      var विकल्प = $ (" # sunSelectedList ")। बच्चों ('विकल्प'); Var विकल्प = कोट = options.length;   

    प्रत्येक विकल्प उपयोग की ऊंचाई प्राप्त करने के लिए या

      options.each (फ़ंक्शन (इंडेक्स, आइटम) {var optionHeight = $ (this)। OuterHeight  

    , चाहे उनके चुने हुए राज्य की परवाह किए बिना। " तो .height () या .outerHeight () वास्तव में हमेशा 0 वापस आएगा। window.getComputedStyle (this, null) का उपयोग करना। LineHeight; भरोसेमंद नहीं है क्योंकि क्रोम वापस सामान्य लौटा सकता है, न कि कोई संख्या। विकल्प की सामग्री को प्रतिलिपि बनाना संभव है एक अस्थायी div तत्व में और ऊंचाई की गणना करें।

      options.each (फ़ंक्शन (इंडेक्स, आइटम) {var temp = $ ('& lt; div & gt; & lt; / Div & gt; ')। पाठ ($ (यह) .text ()); $ (' body ')। अनुलग्नक (temp); console.log (temp.height ()); // या console.log (विंडो। GetComputedStyle (temp [0], null)। Hight); temp.remove ();});    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -