Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.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
Javascript 在jquery中,如何编写一个函数将一个DIV的高度复制到另一个DIV?_Javascript_Jquery_Css_Asp.net - Fatal编程技术网

Javascript 在jquery中,如何编写一个函数将一个DIV的高度复制到另一个DIV?

Javascript 在jquery中,如何编写一个函数将一个DIV的高度复制到另一个DIV?,javascript,jquery,css,asp.net,Javascript,Jquery,Css,Asp.net,考虑以下几点: <div id="outerDIV"> <div id="innerDIV" style="height: 100%;"> <asp:ContentPlaceHolder... /> </div> </div> 但问题是我只希望它在页面的第一次加载时发生。当用户导航到其他页面时,我不希望outerDIV再次调整大小 我怎样才能做到这一点 谢谢你为什么不用饼干呢 并随时使用$.rem

考虑以下几点:

<div id="outerDIV">
     <div id="innerDIV" style="height: 100%;">
         <asp:ContentPlaceHolder... />
     </div>
</div>
但问题是我只希望它在页面的第一次加载时发生。当用户导航到其他页面时,我不希望outerDIV再次调整大小

我怎样才能做到这一点

谢谢你为什么不用饼干呢


并随时使用$.removeCookiesetHeight删除cookie

也许你可以这样做

var applied = 0;/*use it to check if height to outter div has been applied */
$(document).ready(function(){

  if(applied == 0){
  $('#outerDIV').height($('#innerDIV').height());
applied = 1;
}//this way the height will be applied only once

});
从MDN: 将类选择器与ID选择器结合使用

 $(document).ready(function(){
         $('#outerDIV.firstpage').height($('#innerDIV.firstpage').height());
     }
 });

通过添加class='firstpage'选择器,您可以区分第一页和其他页,而无需担心cookie或跟踪其他变量

使用饼干。设置cookie并在加载时对其进行测试换句话说,您不希望在母版页中声明此脚本,而只将其应用于第一个内容页,对吗?然后不要在所有页面中包含此脚本非常重要的阅读:。简而言之,除非服务器需要查看cookies,否则不要设置cookies!正如Jaxo所说,您不应该将cookie用于可以通过HTML类和jQuery选择器控制客户端的东西。
var applied = 0;/*use it to check if height to outter div has been applied */
$(document).ready(function(){

  if(applied == 0){
  $('#outerDIV').height($('#innerDIV').height());
applied = 1;
}//this way the height will be applied only once

});
 $(document).ready(function(){
         $('#outerDIV.firstpage').height($('#innerDIV.firstpage').height());
     }
 });