4 페이지, 4 페이지가 있습니다. 그리고 js 파일에 전역 변수를 저장하면 각 웹 페이지에서 yes/no를 클릭하여 변수를 업데이트하려고합니다. 변수를 보관할 수있는 방법이 있습니까? 예 : webrownser 또는 하드 디스크에 저장 하시겠습니까?동일한 변수를 여러 파일로 업데이트하십시오.
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="js/counter.js"></script>
</head>
<body>
<h1>Are u in?</h1>
<!--img tag-->
<div id="yes">
<input type="button" name="yes" value="Yes">
</div>
<div id="no">
<input type="button" name="yes" value="No">
</div>
<script type = "text/javascript">
$("#yes").click(function() {
count = 1; //page2 will getC() and count += 2 and setC(count)
setC(count);
window.location.replace("page2.html");//maybe this will clear out something
});
$("#no").click(function() {
window.location.replace("page2.html");
});
</script>
</body>
------------ JS 파일 ------------------
var count;
function setC(c){
count = c;
}
function getC(){
return count;
}
나는 Firefox에서 그렇게 할 수 있었지만 Chrome에서는 null이되었습니다. – CodeFarmer
각 브라우저에는 고유 한 쿠키 세트가 있습니다. 따라서 페이지 요청을 수행하지만 브라우저간에 지속되지는 않습니다. 'return $ .cookie ('the_count');'를 $로 변경할 수 있습니다 .cookie ('the_count') || 0;'아무것도 설정되지 않은 경우 기본값 0을 반환합니다. – Paul