【发布时间】:2021-11-29 06:00:55
【问题描述】:
如何在 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也能做到吗?
【问题讨论】:
-
“没有 jquery 也能做到吗?” jQuery 只不过是 JavaScript……任何可以用 jQuery 完成的事情,没有它也可以完成。跨度>
-
是的,我知道,但我想使用原始 JavaScript
-
jsfiddle.net/shvf1r42 - 这是你想要的还是你想用
main_place替换新的div?
标签: javascript html