Javascript 替换html内容的按钮

Javascript 替换html内容的按钮,javascript,html,button,replace,getelementbyid,Javascript,Html,Button,Replace,Getelementbyid,我想在按钮点击时替换div中的一些内容。但不知怎么的,它不起作用。我错过了什么?另一个脚本使用相同的.getElementByID可以很好地工作,我在同一页的iframe的onload中使用了它 这是我的按钮代码: <div class="checkout_shape" id="content1">Content</div> <div><button onclick="GoToShipping()">Click Me</button>&

我想在按钮点击时替换div中的一些内容。但不知怎么的,它不起作用。我错过了什么?另一个脚本使用相同的
.getElementByID
可以很好地工作,我在同一页的
iframe
onload
中使用了它

这是我的按钮代码:

<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>
内容
点击我
//工作功能
函数LoadCart(){
document.getElementById(“content1”).innerHTML=“”;
}
//非工作功能
函数GoToShipping(){
document.getElementById(“content1”).innerHTML=“”;
}

此代码工作正常。你是按类名选择元素吗?@Chaska:不是,我只是用css来设计div。谢谢大家!另一个iframe的onload函数是否会以某种方式覆盖“GotoShipping”函数?但我想这应该是一次性的行动?