2013-01-19 2 views
0

나는 index.html에 텍스트 상자가 있으며 그 값을 가져 와서 다른 html 파일 인 result.html에 넣기를 원합니다.다른 html 파일에 텍스트 상자의 값 가져 오기

<input id="txt2" readonly="true" type="number" value="0" name="score" style="border:none;background-color:#f0f2f7"> 

result.html 텍스트 상자 :이 자동으로 다른로 이동합니다 코드입니다

<input id="txt3" readonly="true" type="number" value="0" name="score" style="border:none;background-color:#f0f2f7"></td> 

index.html을 텍스트 박스 (그들이 사용하여 동일한의 .js 파일이) 페이지 :

if((mins == 0) && (secs == 0)) { 
    //window.alert("Time is up.Your score is "+score); // change timeout message as required 
    document.getElementById('txt2').value = score; 
    window.location = "score.html" // redirects to specified page once timer ends and ok button is pressed 
} 
else { 
    cd = setTimeout("redo()",1000); 
} 

txt3은 다른 html에 있기 때문에 txt2의 가치를 어떻게 얻을 수 있습니까? 사전에

감사합니다. 이

http://mysite.com/index.html?name=john 

처럼

+1

당신이 페이지에 걸쳐 데이터를 지속적으로 유지하기 위해 쿠키를 사용하려고 할 수 있습니다를 통해이 값을 전달 아무 서버 측의 도움이 없다면. – Lix

+0

또는 html5 기능에 대한 연구. 로컬 저장소 같은 것이 있다고 생각합니다. 그것은 당신이 찾고있는 것일 수도 있고 또한 완전히 라인 밖일 수도 있습니다. –

+0

@MAXIMUM 답이 목적을 충족 시키면 녹색 확인 응답을 고려하십시오. http : //meta.stackexchange에 대한 자세한 내용은 여기를 참조하십시오. co.kr/questions/23138/스택 오버플로 수용 방법 –

답변

1

를 사용하여 쿼리 문자열 다음과 같이

function loadPageVar (sVar) { 
    return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(sVar).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1")); 
} 

// Would alert the value of QueryString-variable called name 
alert(loadPageVar("name")); 
1

변경 결과 페이지의 URL 자바 스크립트를 사용하여 다른 HTML 페이지에이 이름을 얻을;

window.location = "result.html?val="+document.getElementById('txt2').value; 

result.html

<input id="txt3" readonly="true" type="number" value="0" name="score" style="border:none;background-color:#f0f2f7"></td> 


<script> 
document.getElementById('txt3').value=window.location.search.replace("?val=",""); 
</script> 
관련 문제