我有一个非常简单的案例,但让我感到困惑,这里是脚本 =>
<!DOCTYPE html>
<html>
<head>
<title>HI</title>
<link rel="stylesheet" href="./scripts/css/default.css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form name="ok" method="post" action="index.php">
<select name="sel" id="sel"><option value="a">1</option><option value="b">2</option><option value="c">3</option></select>
</form>
FIRST PAGE
<div id="as"></div>
<script type="text/javascript">
document.getElementById("sel").onchange = function(){
var doc = false;
if (window.XMLHttpRequest){
doc = new XMLHttpRequest();
}
if(doc){
doc.open("POST","./index.php",true);
doc.onreadystatechange = function(){
if (doc.status==200 && doc.readyState==4){
document.getElementById("as").innerHTML = doc.responseText;
}
};
doc.send("sel=" + document.getElementById("sel").value);
}
};
</script>
<?php
if (isset($_POST['sel'])){
echo $_POST['sel'];
}
?>
</body>
</html>
从这个脚本中,我希望 onselect 更改返回我选择元素的值,但它再次返回整个页面,为什么?有任何想法吗 ?请帮忙,谢谢:))
PS。这是自我 index.php 页面