我有2个HTML页面,Login.html,contactus.html。
TIA
login.html的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script src="./pages/js/service.js"></script>
<script type="text/javascript">
function navigate(url)
{
displayPage(url);
}
</script>
</head>
<body>
<div id="divtohideindex">
<a href="#" onclick="navigate('URLcontactus');">Login</a>
</div>
</body>
</html>
service.js的代码:
function displayPage(url)
{
var targetURL;
targetURL = getResourceLocation(url);
loadResource(targetURL);
//document.getElementById("divtohideindex").style.display='none';
}
function getResourceLocation(resourceName)
{
if (resourceName == 'URLcontactus')
{
return "./pages/contactus.html";
}
}
function loadResource(urlToNavigate)
{
var xmlhttp;
var resp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var str = xmlhttp.responseText;
alert("resp-->"+ xmlhttp.responseText);
var strHtmlContent = str.substring(str.indexOf("<html>"), str.lastIndexOf("</html>"))+"</html>";
window.document.getElementsByTagName('html')[0].innerHTML = strHtmlContent;
}
}
xmlhttp.open("GET", urlToNavigate, false);
xmlhttp.send();
}
contactus.html代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
function validate()
{
alert("in validate()");
}
</script>
</head>
<body>
<h1>Contact Us...</h1>
<input type="text" onkeypress="validate();" value="123" id="id_txtbx">
<div id="myDiv"></div>
</body>
</html>