Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.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/2/jquery/89.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/2/ssis/2.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 关闭并将高度和宽度重置为“上的原始尺寸”;“关闭”;点击_Javascript_Jquery - Fatal编程技术网

Javascript 关闭并将高度和宽度重置为“上的原始尺寸”;“关闭”;点击

Javascript 关闭并将高度和宽度重置为“上的原始尺寸”;“关闭”;点击,javascript,jquery,Javascript,Jquery,我有这个html: <div class="box"> <div class="info"> <p>..some content..</p> <a href="#" class="close">Close</a> </div> </div> <div class="box"> <div class="info"&g

我有这个html:

<div class="box">
     <div class="info">
          <p>..some content..</p>
          <a href="#" class="close">Close</a>
     </div>
</div>
<div class="box">
     <div class="info">
          <p>..some content..</p>
          <a href="#" class="close">Close</a>
     </div>
</div>
当我单击“关闭”一次。长方体已展开时,我应该能够关闭展开的。长方体,并将其高度和宽度重置为展开前的原始大小

我尝试运行此函数,它位于另一个函数中,但没有获得正确的高度:

$(".close").click(function (e) {
    e.preventDefault();
    $(".info").empty();
    $(".box").width(251);
    $(".box").data('height');
});

有人吗?

关于你的.close方法:

$(".close").click(function (e) {
    e.preventDefault();
    $(".info").empty();
    $(".box").width(251);
    $(".box").data('height'); // Just retrieves the height value
});
我想你是想这么做

$(".close").click(function (e) {
    e.preventDefault();
    $(".info").empty();
    $(".box").width(251);
    // Sets the element's height to the stored height value
    $(".box").height( $(".box").data('height') );
});

为什么不能使用标准布局CSS技术来实现这一点?您可以删除或隐藏.info,让“框”返回正常状态。因为实际上,.info中的内容是通过ajax加载的,我正在使用jquery设置新的高度和宽度。关于维梅奥,我们有很多理由这么做。好吧,这是有道理的。现在你已经发布了一个封闭的方法,看看我下面的答案。没问题!如果这解决了你的问题,考虑把这个标记为所选答案。
$(".close").click(function (e) {
    e.preventDefault();
    $(".info").empty();
    $(".box").width(251);
    // Sets the element's height to the stored height value
    $(".box").height( $(".box").data('height') );
});