首页 > 解决方案 > JQuery .width() 不会改变宽度

问题描述

我有两个 div,一个 img 和一个 video,它们会自动调整到屏幕的大小。我希望我的图像与视频的宽度相同,并在网上找到了这段代码(.you是视频,.santa也是图像):

<script> 
    $( window ).resize(function() {
        $(".santa").width($(".you").width());
    });            
</script>

它不会改变宽度。

标签: javascripthtml

解决方案


它改变了我在这里为你写了一个例子的宽度,检查它只是调整页面拆分器的大小

<div class="santa" style="width:100px;background-color:red">
santa
  <div class="you" style="width:200px;background-color:green">
    you
  </div>
</div>

$( window ).resize(function() {
  $(".santa").width($(".you").width());
}); 

推荐阅读