Asp.net 获取自动调整大小的控件的大小?

Asp.net 获取自动调整大小的控件的大小?,asp.net,javascript,vb.net,Asp.net,Javascript,Vb.net,我的情况是,在同一个asp.net页面上有多个listbox控件。它们当前自动调整大小以防止数据被截断。但是,我希望能够确定最大列表框的宽度,然后将其他列表框的大小更改为相同 问题是。。。如何访问列表框的大小?或者我可以吗?是的,你可以 //This is a <div> that wraps around your listboxes var wrapperDiv = document.getElementById('listboxWrapper'); //Get all <

我的情况是,在同一个asp.net页面上有多个listbox控件。它们当前自动调整大小以防止数据被截断。但是,我希望能够确定最大列表框的宽度,然后将其他列表框的大小更改为相同

问题是。。。如何访问列表框的大小?或者我可以吗?

是的,你可以

//This is a <div> that wraps around your listboxes
var wrapperDiv = document.getElementById('listboxWrapper');

//Get all <select> elements within the <div>
var sels = wrapperDiv.getElementsByTagName('SELECT');

//An array to store the width values
var widths = new Array();

//Load the array
for(var i = 0, l = sels.length; i < l; i++)
  widths[i] = sels[i].offsetWidth;

//Get the max width
var maxW = Math.max(widths);

//Set the max width to all the list boxes
for(var sel in sels)
  sels[sel].style.width = maxW;
//这是一个围绕列表框的
var wrapperDiv=document.getElementById('listboxWrapper');
//获取
var sels=wrapperDiv.getElementsByTagName('SELECT');
//用于存储宽度值的数组
变量宽度=新数组();
//加载数组
对于(变量i=0,l=sels.length;i<代码> > p>对于最好的结果,考虑使用JavaScript框架,使用jQuery:

var width = 0;
//get the largest width
$("select").each(function() {
    if ($(this).width() > width) {
        width = $(this).width();
     }
});
//make them all the same width
$("select").css("width", width);

注释使用过多->//获取最大宽度\n var maxW=Math.max(宽度);我知道,但我希望所有Javascript新手都能理解。应该说这是Javascript,所以在服务器上运行客户端,/而不是。@Richard:他的问题被标记为“Javascript”,这正是我要找的。谢谢一个简单的任务不需要一个大的库。