我是角度2的新手。如果我点击任何“按钮”,那只是下一个跨度 闭合。
<div class="parent">
<button>Click</button>
<span>Element One</span>
</div>
<div class="parent">
<button>Click</button>
<span>Element Two</span>
</div>
<div class="parent">
<button>Click</button>
<span>Element Three</span>
</div>
答案 0 :(得分:0)
试试这个: 的 DEMO 强>
HTML:
<div class="parent1">
<button (click)="hide('parent1')">Click</button>
<span #elOne>Element One</span>
</div>
<div class="parent2">
<button (click)="hide('parent2')">Click</button>
<span #elTwo>Element Two</span>
</div>
<div class="parent3">
<button (click)="hide('parent3')">Click</button>
<span #elThree>Element Three</span>
</div>
TS:
export class AppComponent {
hide(parentClass){
let span = document.querySelector("." + parentClass + ' span');
span.style.visibility = 'hidden'
}
}