2014-11-16 2 views
0

저는 Javascript와 래칫 (ratchet)을 처음 사용하는 사람입니다. 익숙해지기 위해 작은 앱을 만들려고합니다. 다음 코드를 작성했지만 제대로 작동하지 않습니다. 뒤로 버튼에서 메모를 저장하는 자바 스크립트를 가져오고 싶습니다. 하지만 note_back()을 찾을 수 없다는 오류가 나타납니다. 내가 뭘 잘못 했니?래칫에서 onclick 이벤트를 사용하는 방법?

index.html을

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title>Notes</title> 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1"> 
    <meta name="apple-mobile-web-app-capable" content="yes"> 
    <meta name="apple-mobile-web-app-status-bar-style" content="black"> 
    <link href="css/ratchet.css" rel="stylesheet"> 
    <script src="js/ratchet.js"></script> 
</head> 
<body> 
    <header class="bar bar-nav"> 
     <a class="icon icon-plus pull-right" data-transistion="slide-in" href="note.html"></a> 
     <h1 class="title">Notes</h1> 
    </header> 
    <div class="content"> 
     <ul class="table-view"> 
     </ul> 
    </div> 
</body> 
</html> 

note.html

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title>Note</title> 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1"> 
    <meta name="apple-mobile-web-app-capable" content="yes"> 
    <meta name="apple-mobile-web-app-status-bar-style" content="black"> 
    <link href="css/ratchet.css" rel="stylesheet"> 
    <script src="js/ratchet.js"></script> 
    <script src="js/notecontroller.js"></script> 
</head> 
<body> 
<header class="bar bar-nav"> 
    <a class="icon icon-left pull-left" onclick="javascript:note_back()"></a> 
    <a class="icon icon-trash pull-right" onclick="javascript:note_delete()"></a> 
    <h1 class="title">Add Note</h1> 
</header> 
<form> 
    <br> 
    <br> 
    <br> 
    <textarea id="notetext" rows="10"></textarea> 
</form> 
</body> 
</html> 

notecontroller.js

function note_back() { 
    console.log("reached note_back"); 
    localStorage.setItem("note",document.getElementById("notetext")); 
    window.location.href="index.html"; 
} 
function note_delete() { 
    console.log("reached note_delete"); 
    localStorage.removeItem("note"); 
    window.location.href="index.html"; 
} 

크레아티닌 eenshot :

enter image description here

+0

ratchet.js가 ajax를 사용하여 페이지 전환에 대한 내용을로드하므로 응용 프로그램이 SPA처럼 작동하므로 note.html이 표시되지 않습니다. Note.html이 검색되고 구문 분석되고 콘텐츠가 스왑 된 다음 창 위치가 기록 API를 사용하여 설정됩니다. – kindasimple

+0

PUSH는 어떻게 호출합니까? 이 문제를 해결하려고합니다. http://stackoverflow.com/questions/30178538/how-do-i-trigger-ratchets-push-manually – jgauna

답변

1

문제는 note.html의 머리 부분에 자바 스크립트 링크가로드되지 않은 것입니다 (측면 질문, 왜 note.html 참조하지 않는?) 그래서 index.html에 자바 스크립트를 모두 넣어야합니다.

래칫은 push.js를 사용하여 탐색합니다. 클릭하여 탐색하면 ratchet가 note.html을 ajax를 통해로드하고 콘텐츠 용 DOM을 파싱하므로 자바 스크립트 포함은 후속 페이지에서 실행되지 않습니다.

스크립트 참조를 index.html로 이동하고 window.location.href (응용 프로그램을 재설정 함)에서 컨트롤러 탐색을 변경하여 PUSH ({}) 메서드 (ratchet.js의 창)에 올바른 옵션을 지정하십시오.

관련 문제