私は次のコードを持っています
<span class="numbers">
<a href="#">20</a>, <a href="#">50</a>, <a href="#">100</a>
</span>
クラス「numbers」は、位置の絶対要素であり、ページ内で複数回使用されます。
クラス「numbers」内のコンテンツは動的に変化します。したがって、子の合計幅をその親コンテナに適用する必要があります
このコードを試しましたが、機能しませんでした。
var totalWidth = 0;
$(".numbers").children('a').each(function() {
totalWidth = totalWidth + $(this).width();
$('.numbers').each(function(){$(this).css("width", totalWidth);});
});
しかし、totalWidth値0のみを取得しています。誰か助けてくれませんか..........?