首页 > 解决方案 > 替换html内容的按钮

问题描述

我想替换按钮单击 div 中的某些内容。但不知何故,它不起作用。我在这里想念什么?另一个具有相同功能的脚本.getElementByID完美运行,我在同一页面上的onloadan 中使用了它。iframe

这是我的按钮代码:

<div class="checkout_shape" id="content1">Content</div>
<div><button onclick="GoToShipping()">Click Me</button></div>

<script>
//Working function
function LoadCart(){
document.getElementById("content1").innerHTML ="<iframe src='/cart' width='100%' height='900px' frameborder='0' scrolling='yes' z-index='-5'></iframe>";
}

//Not working function
function GoToShipping(){
  document.getElementById("content1").innerHTML ="<iframe src='/shipping' width='100%' height='900px' frameborder='0' scrolling='yes' z-index='7'></iframe>";
}
</script>

标签: javascripthtmlbuttonreplacegetelementbyid

解决方案


推荐阅读