我想创建所选元素的每个子元素的宽度数组。我试过了:
var width = $(element).children().map(function () { return this.style.width; });
但这行不通。当我 alert(width[0])
时,它不显示宽度而是显示 objectHtmlElement
。我做错了什么?
最佳答案
尝试 .width()
样式属性仅在设置内联样式时才有效。
var widths = $(element).children().map(function () { return $(this).width(); });
关于javascript - 如何在jquery中创建数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12949397/