如何在javascript中用另一个div替换div?
这就是我所拥有的:
<div id="main_place">
main
</div>
<button onclick="show(operation1)">Replace to operation 1</button>
<button onclick="show(operation2)">Replace to operation 2</button>
<button onclick="show(operation3)">Replace to operation 3</button>
<div id=operation1 style=“display:none”>
Some textboxes and text
</div>
<div id=operation2 style=“display:none”>
Again some textboxes and text
</div>
<div id=operation3 style=“display:none”>
And again some textboxes and text
</div>
<script>
function show(param_div_id){
document.getElementById('main_place').innerHTML = Here should be div from param;
}
</script>
有没有可能在没有jquery的情况下完成呢?
发布于 2016-05-20 21:22:21
将字符串传入您的方法并获取另一个div
<div id="main_place">
main
</div>
<button onclick="show('operation1')">Replace to operation 1</button>
<button onclick="show('operation2')">Replace to operation 2</button>
<button onclick="show('operation3')">Replace to operation 3</button>
<div id=operation1 style=“display:none”>
Some textboxes and text
</div>
<div id=operation2 style=“display:none”>
Again some textboxes and text
</div>
<div id=operation3 style=“display:none”>
And again some textboxes and text
</div>
<script>
function show(param_div_id) {
document.getElementById('main_place').innerHTML = document.getElementById(param_div_id).innerHTML;
}
</script>
发布于 2019-03-06 00:05:30
我用这个表单替换了我的div。
<div id="newDiv" class="here" style="display: none" > content</div>
<div id="oldDiv" class="here" style="display: block"> content</div>
<button type="button" onclick="newDivHere()">replace</button>
和JS:
function newDivHere() {
document.getElementById("oldDiv").style.display="none";
document.getElementById("newDiv").style.display="block";
}
发布于 2021-11-28 22:00:56
试着这样做
document.querySelector('#maincontent').outerHTML = jsonResponse.main;
https://stackoverflow.com/questions/37347690
复制相似问题