如何用javascript中的另一个div替换div? [英] How to replace div with another div in javascript?
本文介绍了如何用javascript中的另一个div替换div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何用javascript中的另一个div替换div?
How to replace div with another div in javascript?
这就是我所拥有的:
<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也可以做到吗?
Is it even possible to do it without jquery?
推荐答案
将字符串传递到您的方法中并获取另一个div
Pass strings into your method and get the other 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>
这篇关于如何用javascript中的另一个div替换div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文