【问题标题】:Click photo slideshow点击照片幻灯片
【发布时间】:2023-03-28 09:17:01
【问题描述】:

我试图让我的照片在单击每一张时按顺序显示。 当我点击第一张图片时,它会转到第二张图片,但第三张图片却不一样。

首页代码:

<script>
function loadXMLDoc()
{
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)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajax_info.html",true);
xmlhttp.send();
}
</script>



<div id="myDiv">

<h2><a><button type="submit" onclick="loadXMLDoc()"><img src="/project2_ver3/vor/pic5.jpg" alt="vor" width="540" height="418"/></a></button></h2>

</div>

然后是ajax_info.html处的代码:

<!DOCTYPE html>
<html>
<body>

<script>
function loadXMLDoc2()
{
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)
    {
    document.getElementById("myDivv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","\project2_ver3\ajax_infoo.html",true);
xmlhttp.send();
}
</script>



<div id="myDivv">

<h2><button type="submit" onclick="loadXMLDoc2()"><img src="/project2_ver3/vor/pic2.jpg" alt="vor" width="540" height="418"/></button></h2>

</div>




</body>
</html>

最后,ajax_infoo.html处的代码:

(代码修剪):

xmlhttp.open("GET","ajax_infooo.html",true);
xmlhttp.send();
}
</script>
<div id="myDiv">
<h2><button type="submit" onclick="loadXMLDoc2()"><img src="/project2_ver3/vor/pic1.jpg" alt="vor" width="540" height="418"/></button></h2>
</div>
</body>
</html>

【问题讨论】:

标签: html ajax


【解决方案1】:

问题是您要替换完整的“myDiv”innerHTML。这样做将停用您为按钮编写的 onclick 函数。 尝试解决这个问题。应该可以解决的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-26
    • 1970-01-01
    • 2023-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多