我的代码是
<html>
<head>
<script type="text/javascript">
function changeImage(i) {
var hed = document.getElementById("hed");
switch (i) {
case 'a':
hed.src = "header.php";
break;
default:
return false;
}
}
</script>
</head>
<body bgcolor="#FFFFFF">
<div align="center">
<input type="button" value="Previous-Day" onClick="changeImage('a');"> Type of Index:
<img id="hed">
</div>
</body>
</html>
<?php
echo "alpha";
?>
问题是,&#34; alpha&#34;执行menu.php时不显示消息。 (而是显示“未找到图像”图标)。我的目的只是为了显示消息&#34; alpha&#34;,我应该怎么做以实现上述代码? -
答案 0 :(得分:0)
尝试类似这样的事情
<script type="text/javascript">
function loadXMLDoc(id)
{
var xmlhttp;
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)
{
//alert(xmlhttp.responseText);
document.getElementById(id).src=xmlhttp.responseText;
return xmlhttp.responseText;
}
}
xmlhttp.open("GET","data.php",true);
xmlhttp.send();
}
function changeImage(i) {
var hed = document.getElementById("hed");
switch (i) {
case 'a':
loadXMLDoc(hed);
break;
default:
return false;
}
}
</script>