Javascript 如何使用jquery获取div的宽度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11033322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 04:08:12  来源:igfitidea点击:

How to get width of div using jquery

javascriptjqueryhtmlcss

提问by Pulkit

How to get width of div using jquery

如何使用jquery获取div的宽度

$("#window").width();is not working

$("#window").width();不管用

 <div id="widnow"></div>

CSS:

CSS:

#widnow{
  width:500px;
  border:solid 1px;
  float:left;
}

回答by Mike Bonds

It looks like you have made a simple mistake.

看起来你犯了一个简单的错误。

Try changing

尝试改变

$('#window').width();

to

$('#widnow').width();

From what you have displayed here, you have misspelled window as widnow.

根据您在此处显示的内容,您将 window 拼错为widnow

回答by Rinkal Bhanderi

Here you go...

干得好...

var width = $("#window").width();

var width = $("#window").width();

回答by mgraph

try:

尝试:

$(document).ready(function(){
   alert($("#window").width());
})

回答by Ashley

Use jquery Width command with the jcrop boxWidth, create a div layer around the image and then find the width using the command!

使用 jquery Width 命令和 jcrop boxWidth,在图像周围创建一个 div 层,然后使用命令找到宽度!

boxWidth: $("#cropwindow").width(),

this will give you the width of the responsive area!

这将为您提供响应区域的宽度!