English 中文(简体)
最多
原标题:get highest div
  • 时间:2012-01-15 21:57:50
  •  标签:
  • jquery
  • html

我看到了几批高射机上的许多事情,只有为我工作的非。 我需要获得四肢检查的高度。

<div class="headline" data-rating="0.482005543693" onclick="javascript:showArticle(1076);" style="display: none; ">
    <div class="headline_txt">
        <h1>#3726: Meryl Streep schittert in The Iron Lady- alle recensies op een rijtje</h1>
    </div>
    <div class="preview_txt">
        <p>
            De eerste foto s van actrice Meryl Streep als de Britse voormalig premier Margaret Thatcher
            <a href="http://www.guardian.co.uk/film/2011/feb/08/meryl-streep-margaret-thatcher-iron-lady#">
                leidden
            </a>
            vorig jaar al tot een stortvloed aan publiciteit. Nu is
            <a href="http://www.imdb.com/title/tt1007029/">
                <em>The Iron Lady</em>
            </a>
             er dan ook echt. Vanaf vandaag draait de film in de Nederlandse bioscopen. Lees hier alle recensies. 
            <!--more-->
        </p>
    </div>                  
</div>

从表面上看,我最喜欢:

var maxHeadLineHeight = Math.max.apply(Math, $("#headline").map(
    function(){
        return $(this).height();
    }
));

console.log("maxHeadLineHeight: "+maxHeadLineHeight);

但这使我:

<编码> UncaultographError: Function.prototype.apply: Arguments list has wrong category

我也试图这样做:

"#headline .preview_txt"

while where at it, setting the height for each headline div will be next but that probably won t be that different (by getting the objects).

最佳回答

There are two problems with the code:

1. Your selector is wrong.

$("#headline") will find an element with an id of headline, not a class of headline.

Try this instead:

$(".headline").map(...

2. You forgot to include .get() after .map()

我不敢肯定,为什么这一点很重要,但与你发出的守则相似的例子表明,你需要:

$( <someSelectorHere> ).map(function () { /* some mapping code here ... */ })
    .get(); // <-- The part you missed - won t work without it

See this example:

Edit:

根据评论和jQuery docs,似乎称“.get(meth很重要,因为被j Query送回的物体是真正的阵列——它们只是作为阵列。 虽然有些浏览器(似乎有色人种),但其他浏览器却无法处理。 因此,你需要增加<代码>.get(),以便转换成真正的阵容,支持这些浏览器。

Demo of a working version of the code you provided:

The Javascript from that demo:

var headlineHeights = $(".headline").map(function() {
    return $(this).height();
}).get();

var maxHeadLineHeight = Math.max.apply(Math, headlineHeights);

alert("maxHeadLineHeight: " + maxHeadLineHeight);
问题回答

Hmm,这似乎在燃烧中。 在该网页上,以下法典提供了答案(至少是我的浏览器中的625个)。

Math.max.apply(Math, $("#question").map(
 function(){
   return $(this).height();
 }
));

或显然是其他浏览器

Math.max.apply(Math, $("#question").map(
 function(){
   return $(this).height();
 }
).get());

但是,这是很奇怪的,因为在你的法典中,你检查了一张身份证(0或1个元件),并且说这非常明显。 因此,我认为还有一点是错误的。 如果把点数改为点头,则我期望得到很好的答案。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签