简体   繁体   English

从一个div移到另一个

[英]move from one div to another

Currently I have only contents of div=content2 visible on my screen. 目前,我的屏幕上仅可见div=content2内容。 It has some content and a button. 它具有一些内容和一个按钮。 All other div's content are not visible (the display style of other div's are set to none) Now when I click on the button I want the content of only div=ContentXYZ to be displayed. 其他所有div的内容都不可见(其他div的显示样式设置为none)现在,当我单击按钮时,我只希望显示div=ContentXYZ的内容。 Basically I want to move from current div content to a different div content. 基本上,我想从当前的div内容移动到其他div内容。

I don't want anything from my current screen to be visible I just want all the contents of another div to be displayed. 我不希望显示当前屏幕上的任何内容,而只希望显示另一个div的所有内容。

With Javascript you can alter the display properties of the divs. 使用Javascript,您可以更改div的显示属性。 You could add a onclick function to your button where you change the styling of the div element. 您可以在按钮上添加onclick函数,以在其中更改div元素的样式。

function displayDiv(){
   document.getElementById("ContentXYZ").style.display = "inline";
}

A working sample 工作样本

HTML 的HTML

<div id="content2">
    Content 2 goes here
    <button id="btn">Change Div</button>
</div>

<div id="contentXYZ" style="display:none;">
    Content XYZ goes here
</div>

Javascript Java脚本

$('#btn').on('click',function(){
    $('#content2').css('display','none');
    $('#contentXYZ').css('display','block');
});

more reference: Replace Div Content onclick 更多参考: 替换Div内容onclick

The most angular way to do it would probably be with ng-class. 最有角度的方法可能是使用ng-class。 ng-class conditionally applies a class for example: ng-class有条件地应用一个类,例如:

ng-class="{'visible': div1}"

This would apply class visible if div1 is true. 如果div1为true,则将应用可见的类。

Here is a working example: https://plnkr.co/edit/q2XzDbdxPMBFJUl5X7kl?p=preview 这是一个工作示例: https : //plnkr.co/edit/q2XzDbdxPMBFJUl5X7kl?p=preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM