2011-03-04 76 views
0

我有一些代码,以确保这两个具有ID的内容和txtCotent的div是相同的高度。任何想法为什么这个jQuery不会在IE中工作,但在Firefox中工作

<script language = "javascript" src = "js/jquery.js"></script> 
    <script> 
    $(document).ready(function() { 

    var h = $('#wrapContent#').css('height'); 
    $('#content, #txtContent').css('height', h); 
           }); 
    </script> 

任何想法,为什么这不会在IE中工作?这里是链接... http://students.uwf.edu/bmg17/workshop/index.cfm

+0

Bri你实际上有2个div,其内容的ID实际上可能会在jQuery中造成严重破坏。您应该将ID更改为唯一。 – 2011-03-04 22:33:36

回答

1

尝试:

$(document).ready(function() { 

    var h = $('#wrapContent').height(); 
    $('#content, #txtContent').css('height', h + 'px'); 
}); 

编辑:更改为height(),而不是css('height')

+0

总是......很琐碎; ;谢谢。 – Bri 2011-03-04 22:06:03

+0

实际上,我添加了+'px'现在在firefox中不起作用。哈哈。 – Bri 2011-03-04 22:07:05

+0

我打印出h中的内容,并且显示1014px ...所以在添加'px'之前。 :\嗯。 – Bri 2011-03-04 22:15:25

2
$('#content, #txtContent').css('height', h); 

^h应该等于h + 'px'

你需要表达单位,在这种情况下,PX =像素。

1

如上,因为正在使用的CSS()你必须为“高度”指定以像素为单位,但是,如果使用高度()中提到代替可以这样做:

<script> 
$(document).ready(function() { 

var h = $('#wrapContent#').height(); 
$('#content, #txtContent').height(h); 
          }); 
</script> 

不指定像素因为如果没有给出任何单位,jQuery将假定像素。尽管如果需要可以指定一个不同的单位。

相关问题