我对js一般都是新手,但是从我看过的教程看来,这似乎应该有效。我只是试图使用这个插件使3个盒子的高度相等......如果重要的话,盒子有边框半径和其他一些样式。
脚本代码:
$.fn.equalHeights = function(px) {
$(this).each(function(){
var currentTallest = 0;
$(this).children().each(function(i){
if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
});
if (!px && Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
// for ie6, set height since min-height isn't supported
if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
$(this).children().css({'min-height': currentTallest});
});
return this;
};
// just in case you need it...
$.fn.equalWidths = function(px) {
$(this).each(function(){
var currentWidest = 0;
$(this).children().each(function(i){
if($(this).width() > currentWidest) { currentWidest = $(this).width(); }
});
if(!px && Number.prototype.pxToEm) currentWidest = currentWidest.pxToEm(); //use ems unless px is specified
// for ie6, set width since min-width isn't supported
if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'width': currentWidest}); }
$(this).children().css({'min-width': currentWidest});
});
return this;
};
网页代码:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.9.0.min.js"><\/script>')</script>
<script src = "js/jQuery.equalHeights.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(function(){ $('#equalize').equalHeights(); });
});
</script>
我已经将“均衡”的id应用到包含我想要相同高度的三个盒子的div中。它似乎没有效果,IE抛出脚本错误“$ .browser.msie是null或不是对象”。
我正在使用xampp在php页面上本地运行,如果这是适用的。
我非常肯定这只是我的一个愚蠢的新错误,我认真花了2个小时试图追逐它而我放弃了。如果有人可以插话,我真的很感激!
谢谢, 乔