jquery mobile を使用した複数ページのデザインがあります。最初のサイトでは、onklick() を使用して関数を呼び出し、グローバル配列に値を入力します。この値を 2 番目のサイトに表示したいのですが、document.write(array) で表示できません。
3144 次
1 に答える
0
DOM にデータを追加するには、最初に追加する要素を選択する必要があります。次に、配列を反復処理して、各インデックスの値を DOM に追加します。
//here is the array of values
var myArr = [...];
//wait for out page to initialize
$(document).delegate('#my-page-id', 'pageinit', function () {
//create an array to buffer the output
var output = [];
//use a fast loop to add the value at each index to an array,
//in this case I'm adding some HTMl markup to it as well
for (var i = 0, len = myArr.length; i < len; i++) {
output.push('<li>' + myArr[i] + '</li>');
}
//check to see if there were any indexes in the array
if (output.length) {
//append a list-view widget with the info from myArr to the content section of the current page
$(this).children('.ui-content').append('<ul data-role="listview">' + output.join('') + '</ul>').trigger('create');
}
});
ドキュメントdocument.write
: https://developer.mozilla.org/en/document.write
いくつかのループ間のパフォーマンスの違いを示す JSPerf は次のとおりです: http://jsperf.com/jquery-each-vs-for-loops/2
于 2012-04-12T16:22:21.727 に答える