這是小提琴:http://jsfiddle.net/aSJSm/1/
這裏是代碼:
<html>
:
<ul>
<li><a href="javascript:void(0)">Item1 bla bla bla</a></li>
<li><a href="javascript:void(0)">Item2</a></li>
<li><a href="javascript:void(0)">Item3</a></li>
<li><a href="javascript:void(0)">Item4 ala bala bala</a></li>
<li><a href="javascript:void(0)">Item5</a></li>
<li><a href="javascript:void(0)">Item6</a></li>
<li><a href="javascript:void(0)">Item7</a></li>
<li><a href="javascript:void(0)">Item8</a></li>
</ul>
<css>
:
ul{
width: 200px;
float:none;
}
ul li a{
width: 50%;
float: left;
border-bottom: 1px solid black;
}
<javascript>
:
var setList = function(){
var listItems = $('ul').children();
$.each(listItems, function(index){
if (index % 2 == 0){
var leftElementHeight = $(this).children('a').height();
var rightElementHeight = $(this).next().children('a').height();
if (leftElementHeight < rightElementHeight)
$(this).children('a').css("height", rightElementHeight);
else
$(this).next().children('a').css("height", leftElementHeight);
}
});
}
setList();
確保你包含在$(document).ready(function(){})中,並且你有最新的jquery。
偉大的作品 - thx! :) – brother