2012-04-05 7 views
1

JQM을 처음 사용합니다. 나는 내가 예를 들어 div 태그 를 사용하여 많은 페이지를 만든있는 index.html 파일을 JQM에서 페이지 ID를 사용하여 페이지 새로 고침

<div data-role="page" id="pg1 "></div> 

지금 내가) (id..how이 사용 location.reload을 수행하는 페이지를 사용하여 특정 페이지를 다시로드 할

, 또는 다른 방법 라운드 ??

덕분에 ..

답변

1

당신이 단지에 존재하기 때문에 당신은 기본적으로 페이지를 새로 고칠 수 없습니다, 모든 의사 페이지를 하나의 문서에 여러 페이지 템플릿을 사용하는 경우 현재 DOM. 당신은에 대한 이벤트 처리기에서이 코드를 사용할 수

function replace_multipage_template (SELECTOR) { 

    //show the loading spinner 
    $.mobile.showPageLoadingMsg(); 

    $.ajax({ 

     //request the same document as the current URL 
     url  : window.location.href, 
     success : function (response) { 

      //select just the desired pseudo-page 
      var $ele = $(response).find(SELECTOR); 

      //replace the current pseudo-page with the new one 
      $(SELECTOR).replaceWith($ele); 

      //hide the loading spinner 
      $.mobile.hidePageLoadingMsg(); 

      //navigate to the refreshed pseudo-page 
      $.mobile.changePage($ele); 
     }, 
     error : function (jqXHR, textStatus, errorThrown) { /*make sure to handle errors*/ } 
    }); 
} 

: 당신은 DOM에서 현재 페이지를 Ajax 요청에 동일한 문서를 요청하고 응답에서 의사 페이지를 잡고 대체하는 기능을 쓸 수있다 페이지로 사용자를 직접 링크에 대한 click 이벤트는 새로 고침 할 :

//bind via delegation to the click events for links that target a specific pseudo-page 
$(document).delegate('a[href="#some-page-id"]', 'click', function() { 

    //call the function from above, using the HREF attribute as the SELECTOR variable 
    replace_multipage_template($(this).attr('href')); 

    //prevent the default behavior of the link 
    return false; 
});