我正在更新问题。为了简化情况,我在index.php文件中有这个脚本
<form name="f" action="index.php" method="post">
<input type="button" name="but" id="but" value="Retrieve">
<div id="div"></div>
<input type="submit" name="ok">
</form>
<script type="text/javascript">
document.getElementById("but").onclick = function(){
var http = false;
if (window.XMLHttpRequest){
http = new XMLHttpRequest();
} else {
http = new ActiveXObject("Microsoft.XMLHttp");
}
if (http){
http.open("POST","other.php",true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function(){
if (http.status==200 && http.readyState==4){
document.getElementById("div").innerHTML = http.responseText;
}
};
http.send(null);
}
};
document.getElementById("y").onclick = function(){
alert("okaaay");
};
</script>
并有other.php文件与下面的脚本
<?php
echo "<input type='text' name='y' id='y'>";
?>
Ajax 脚本工作得很好,但我的问题是,当在 index.php 页面中检索这个标记的输入元素时,使用第二个 JavaScript 代码我无法操作它,请帮助,谢谢 :)