2012-04-12 4 views
0

jquery 모바일을 사용하는 다중 페이지 디자인이 있습니다. 첫 번째 사이트에서 onklick() 함수를 호출하여 값이있는 전역 배열을 채 웁니다. 지금은 두 번째 사이트에이 값을 표시 할,하지만 난 document.write를 (배열)jquery 모바일 멀티 페이지가있는 전역 변수

+0

: 일부 루프 사이의 성능 차이를 보여주기 위해 여기에 https://developer.mozilla.org/en/document.write

JSPerf된다

//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에 대한 : 다음 경우에 DOM에 각 인덱스의 값을 추가하는 배열을 반복 whe n "site"라고 말하면 페이지 (data-role = "page")를 참조하고 있습니까? – JonWells

+0

예. 나는 어떻게 든 페이지 (data-role = "page")가로드 될 때 javascript를 시작해야한다고 생각한다. 자바 스크립트 파일이 홀 html 파일에 링크되어 있기 때문에 전역 배열이 표시되어야합니다. – AdrianoCelentano

답변