Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 具有click事件的卡组件内的Bootstrap 4按钮_Html_Twitter Bootstrap_Angular_Typescript - Fatal编程技术网

Html 具有click事件的卡组件内的Bootstrap 4按钮

Html 具有click事件的卡组件内的Bootstrap 4按钮,html,twitter-bootstrap,angular,typescript,Html,Twitter Bootstrap,Angular,Typescript,我有下面的html代码来使用Bootstrap4生成基本卡。 我想在单击卡片时更改卡片的样式。但是,如果单击按钮,我不希望样式更改。 此时,当我单击test1按钮时,我还将激活onCardClick()函数。 有没有一种方法可以这样做,当我单击test按钮1时,只执行Test1() 一些头衔 测试1 测试2 您可以尝试以下方法来阻止事件在dom中冒泡: <div class="container"> <div class="row"> <div cla

我有下面的html代码来使用Bootstrap4生成基本卡。 我想在单击卡片时更改卡片的样式。但是,如果单击按钮,我不希望样式更改。 此时,当我单击test1按钮时,我还将激活onCardClick()函数。 有没有一种方法可以这样做,当我单击test按钮1时,只执行Test1()


一些头衔
测试1
测试2

您可以尝试以下方法来阻止事件在dom中冒泡:

<div class="container">
  <div class="row">
    <div class="col-md-4">
      <div class="card"
           (click)="onCardClick()">
        <div class="card-block">
          <h4 class="card-title d-inline">Some Title</h4>
          <button class="btn btn-primary"
                  (click)="onTest1($event)">test1
          </button>
          <button class="btn btn-primary"
                  (click)="onTest2($event)">test2
          </button>
        </div>
      </div>
    </div>
  </div>
</div>

你用的是角度?如果是这样,也发布代码。
<div class="container">
  <div class="row">
    <div class="col-md-4">
      <div class="card"
           (click)="onCardClick()">
        <div class="card-block">
          <h4 class="card-title d-inline">Some Title</h4>
          <button class="btn btn-primary"
                  (click)="onTest1($event)">test1
          </button>
          <button class="btn btn-primary"
                  (click)="onTest2($event)">test2
          </button>
        </div>
      </div>
    </div>
  </div>
</div>
import {Component} from "@angular/core"

@Component({
    selector: 'test',
})

export class Test
{
    onTest1(event)
    {
        event.stopPropagation();
        //or event.preventDefault()
        //stuff to run
    }

    onTest2(event)
    {
        event.stopPropagation();
        //stuff to run
    }

}