jQuery Mobile の PageShow イベントを使用して、特定の入力要素の幅を設定しています。ページを直接 (つまり、URL を介して) ロードすると、すべてが期待どおりに機能します。
標準の ajax ナビゲーション システム (つまり、アプリ内リンク) を介してページを読み込むと、「hello」アラートと「span.add-on」の正しい幅が表示されますが、「div.content-padd」は要素の幅がゼロになる? 「div.content-padd」は、ページ内の他のすべての要素のコンテナ要素であり、パディングなどを提供します。すべての JS は Rails レイアウト テンプレートにロードされます。
ここで何が起こっているのかわかりません。私のコードは以下の通りです:
$(document).bind('pageshow', function() {
alert('hello')
$('.add-on').addClass('ui-corner-all');
//Set the width of the input following the appends or prepends to the remaining space
var containerWidth = $('div.content-padd').width();
console.log('container width:' + containerWidth);
var appendsAndPrepends = '.input-prepend, .input-append';
$(appendsAndPrepends).each(function () {
var remainingSpace = containerWidth - $(this).find('span.add-on').outerWidth();
console.log('span width' + $(this).find('span.add-on').outerWidth());
$(this).find('div.ui-input-text').outerWidth(remainingSpace);
});
});