如何在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 是否可以做到这一点?
将字符串传递到您的方法中并获取另一个 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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)