2014-01-28 2 views
0
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <script src="JavaScript/CommonJS.js"> 
    </script> 
</head> 
<body bgcolor="pink">  
    <div align="center" > 
     <h1> <font color="red" >JavaScript task</font></h1> 
    </div> 

    <div align="left" style="font-family:Verdana; font-size:13px"> 
     Number of Characters Left: 
     <label id="lblcount" style="background-color:#E2EEF1; 
        color:Red;font-weight:bold;">100</label><br/> 
     <textarea style="overflow:auto;resize:none" id="mytextbox" 
       rows="4" cols="50" maxlength="100" wrap="hard" 
      onkeyup="LimtCharacters(this,100,'lblcount');"></textarea> 
    </div>   

    <p align="center"> 
     <input type="button" id="view" name="view" 
       value="Next" onclick="SaveData()">    
    </p>   
</body> 

내가 거기에 다음 버튼이 CommonJS.js (자바 스크립트)로가는 클릭하면이 내의 index.jsp 페이지입니다 난 '쿠키에 데이터를 저장하고 내가 쿠키를 읽고 내 resul.jsp 페이지(Result.jsp) 때 몸의 온로드

자바 스크립트에 표시 할 수있는 방법 Result.jsp 페이지에서, Result.jsp에 전달 해요 것은 :

function LimtCharacters(txtMsg, CharLength, indicator) { 
var chars = txtMsg.value.length; 
document.getElementById(indicator).innerHTML = CharLength - chars; 
if (chars > CharLength) { 
    txtMsg.value = txtMsg.value.substring(0, CharLength); 
} 
} 

function createCookie(cname,cvalue,exdays) { 
if (exdays) { 
    var date = new Date(); 
    date.setTime(date.getTime()+(exdays*24*60*60*1000)); 
    var expires = "; expires="+date.toGMTString(); 
} 
else expires = ""; 
document.cookie = cname+"="+cvalue+expires+";path=/"; 
} 

function readCookie(name) { 
var nameEQ = name + "="; 
var ca = document.cookie.split(';'); 
for(var i=0;i < ca.length;i++) { 
    var c = ca[i]; 
    while (c.charAt(0)==' ') c = c.substring(1,c.length); 
    if (c.indexOf(nameEQ) == 0) 
     return c.substring(nameEQ.length,c.length); 
} 
return null; 
} 

function eraseCookie(name) { 
    createCookie(name,"",-1); 
} 

아무도 나에게 감사를 안내 전진.

답변

1

body onload = "functioncall()"지시문을 사용하여로드 할 때 함수를 호출 할 수 있습니다. 그것을 표시하기위한 간단한 방법은 자바 스크립트의 쿠키 값으로 채워지는 div를 페이지에 넣는 것입니다.

코드는 다음과 같을 것이다 :

<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <script type="text/javascript"> 
    function displayCookie() { 
     document.getElementById('myDiv').innerHTML = readCookie('myCookie'); 
    } 
    </script> 
</head> 
<body onload="displayCookie()">  
    <div id="myDiv" ></div> 
</body>