jquery更改div的宽度
问题描述:
我想更改使用以下代码呈现的元素的宽度。我已经尝试在定义中添加样式宽度:xxpx元素,并尝试定义一个新的CSS类来使用。我希望主容器下的容器大小相同。但下面的代码呈现大约40-60。我使用jquery ui的样式表(jquery-ui-1.7.1.custom.css)。jquery更改div的宽度
this.container = $('<div class="ui-multiselect ui-helper-clearfix ui-widget" ></div>').insertAfter(this.element);
this.availableContainer = $('<div class="ui-widget-content list-container available"></div>').appendTo(this.container);
this.selectedContainer = $('<div class="ui-widget-content list-container selected"></div>').appendTo(this.container);
帮助?
答
var newWidth = this.container.width()/2; //I assume you want the child divs to be half the size of the parent?
this.availableContainer.width(newWidth);
this.selectedContainer.width(newWidth);
这是怎么做你问的,用jQuery改变DIV的宽度。
如果您的网站/应用程序预计在没有JavaScript的情况下运行,您可能应该继续抨击CSS并尝试获取样式表设置的样式。
链接到工作示例:http://jsfiddle.net/Phu6y/5/
试过,但没有奏效。 – Chandra 2011-02-10 01:30:36