我是角度和前端開發的新手。我有一個盒子放在另一個盒子的頂部,它們都有自己單獨的點擊事件。上面的盒子是藍色的,后面的盒子是紅色的。每當我點擊藍色框時,紅色框的點擊事件也會注冊。這是代碼。另外請不要使用 event.preventDefault(); event.stopPropagation(); 如果你的回答是因為它過去給我帶來了麻煩。
box1() {
console.log("box 1");
}
box2() {
console.log("box 2");
}
.box1{
left : 100px;
top: 100px;
width: 400px;
height: 400px;
background-color: red;
}
.box2{
position: relative;
left : 100px;
top: 100px;
width: 400px;
height: 400px;
background-color:blue;
}
<div class="container">
<div class="box1" (click)="box1()">
<div class="box2" (click)="box2()">
</div>
</div>
</div>
uj5u.com熱心網友回復:
我已經查看了你的代碼,我對你的 css 和 html 做了一點點改動,它的作用就像一個魅力。
盒子.html
<div class="container">
<div class="box1" (click)="box1()"></div>
<div class="box2" (click)="box2()"></div>
</div>
盒子.css
.box1 {
position: fixed;
left: 100px;
top: 100px;
width: 400px;
height: 400px;
background-color: red;
z-index: 0;
}
.box2 {
position: fixed;
left: 200px;
top: 200px;
width: 400px;
height: 400px;
background-color: blue;
z-index: 999;
}
.container {
position: relative;
left: 100px;
top: 100px;
}
box.ts
box1() {
console.log("box 1");
}
box2() {
console.log("box 2");
}
作業演示:https : //stackblitz.com/edit/angular-ivy-rxyqcd?file= src/app/ app.component.ts
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/371413.html
標籤:javascript html css 有角的 打字稿
上一篇:如何重構三元運算子
下一篇:反應組件道具拋出錯誤打字稿
