Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery高度(值)有问题_Jquery_Asp.net_Visual Studio 2010 - Fatal编程技术网

jQuery高度(值)有问题

jQuery高度(值)有问题,jquery,asp.net,visual-studio-2010,Jquery,Asp.net,Visual Studio 2010,我对jQuery非常陌生,从今天起就开始使用它,所以我打赌我错过了一些非常明显的东西 我正在VS2010中使用jQuery1.5.2和ASP.NET3.5。我试图动态地将一个div容器的高度设置为另一个div容器的高度。后一个div增长以容纳其中的内容,我需要两者高度相等,否则看起来很糟糕 我在Site.master文件的头中尝试了以下代码: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/li

我对jQuery非常陌生,从今天起就开始使用它,所以我打赌我错过了一些非常明显的东西

我正在VS2010中使用jQuery1.5.2和ASP.NET3.5。我试图动态地将一个div容器的高度设置为另一个div容器的高度。后一个div增长以容纳其中的内容,我需要两者高度相等,否则看起来很糟糕

我在Site.master文件的头中尝试了以下代码:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var newHeight = $("#content").height() + "px"; //Also tried without  + "px"
        $("#sidebar").height(newHeight);
    });
</script>
这是在做什么。第一个div的顶部与第二个div的底部内联渲染;不过,我不太确定他们的身高是否相同

我现在正在火狐10.0.2上使用它;我没有检查任何其他版本或浏览器

感谢您的帮助。

首先:。高度不带px

第二:此代码将边栏的高度设置为文档完全加载时内容的高度

所以,如果你只是想这么做,这段代码应该足够了

但是,如果元素的高度像ajax请求一样进行了动态更改,以获取更多内容,然后将其设置为content,则每次更改内容高度时都必须调整侧栏高度

关于这些元素的位置问题,css中应该有一些错误。。关于它们的浮点属性的一些信息。

这对我很有用:

<div id="content" style="float:left; width:100px; height: 200px; background: red;">This is the content</div>
<div id="sidebar" style="float:left; width: 50px; background: blue;">This is the sidebar</div>​

$(document).ready(function () {
    var newHeight = $("#content").height();
    $("#sidebar").height(newHeight);
});

如果没有px,它可以正常工作

您还可以使用jQuery API,并尝试使用equalizeHeights来执行此操作,如本例所示:


使用cosole.log或alert,没有“px”的newHeight的值是多少,因为它不是必需的?错误是由我的css组合而成的,不知何故,我在代码中颠倒了内容和侧边栏的顺序。我可能是想巧妙地处理一些通常会适得其反的事情。谢谢