幅の異なるいくつかの要素があります。私はそれぞれをループする必要があります、幅の幅を見つけ、その幅にすべてを設定します。すべての要素を幅の最も広い幅に設定する
<div id="mySet">
<span>some content</span>
<span>more content</span>
<span>here content</span>
</div>
JS:
var widest = 0;
$("#mySet span").each(function(){
var this = $(this),
wdth = this.width();
if(wdth > widest){
widest = wdth;
$("#mySet span").each(function(){
$(this).width(widest);
});
}
});
私は最大幅を取得しますが、私のループに各要素に幅を割り当てるたびに行うことができると思います。あまりにも多くのループのようです。すべてspan
に幅を設定するには
省略記号は何をしますか? – santa
この場合、mapによって返された配列の各幅をとり、それぞれをmax関数の別々の引数として渡します – searlea