罪惡的IE6不支持max-height屬性,不過我們可以通過jQuery來解決IE6不支持max-height,jQuery的代碼如下:
$(".entry").each(function(){
if($(this)[0].scrollHeight>500)
$(this).css({"height":"500px"});
});
原理: 在IE6中可以通過設定height來達到max-height的效果. 循環所有要加max-height屬性的DOM元素,判斷他的scrollHeight大于你要設置的最大高度 如果超過了就通過設置height為最大高度,我這里使用的是[0],獲取的是的DOM對象,而不是jQuery對象,詳細說明見:《jQuery選擇器使用詳解》
上面的代碼還沒有加入IE6的判斷,完整代碼如下:
if($.browser.msie&&($.browser.version === "6.0")){
$(".entry").each(function(){
if($(this)[0].scrollHeight>500)
$(this).css({"height":"500px","overflow":"hidden"});
});}
當然你也可以通過css表達式來實現IE6支持max-height屬性
.entry{
//我燒驗證woshao_985140e4b71711df9e5e000c295b2b8d
height: expression( this.scrollHeight > 500 ? "500px" : "auto" ); /* sets max-height
原文:http://www.js8.in/606.html