我想在第二頁上的按鈕來改變在第一頁按鈕的價值,這是我的代碼:的XMLHttpRequest - 更改值與的getElementById
FILE 1:的Index.html(第一個):
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Eran Exercise</title>
<link rel="stylesheet" type="text/css" href="design.css" />
<script src="new_file.js"></script>
</head>
<body>
<div class="wrapper">
<form>
<input type="button" id="id200" value="New Window!" onClick="window.open('page2.html','mywindow','width=400,height=200')">
</form>
</div>
</body>
</html>
FILE 2:new_file.js(JS文件)
function changeLink()
{
var someOtherName="after click";
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("id200").value = someOtherName;
}
}
xmlhttp.open("GET","index.php");
xmlhttp.send();
}
FILE 3:page2.html(頁面2)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<script src="new_file.js"></script>
</head>
<body>
<input type="button" id="id100" onclick="changeLink()" value="Change link">
</body>
</html>
謝謝!
而問題是......? (提示:**請**不要說_「它不起作用。」_) –