如何禁用复选框输入标签的特定部分?

时间:2019-07-29 09:48:34

标签: html css

我想问一些关于html和/或css的问题。

我创建了一个复选框输入及其标签,每当用户单击该标签时,该复选框便被打勾/未打勾,但是我在标签中间插入了一个链接,以显示一些弹出模式,现在是标签的行为是,每当用户单击该模式链接时,该复选框也会被单击和打勾/取消勾号,我该如何做,以便当用户单击链接时,该复选框也不会被单击?

<div class="form-check">
  <input type="checkbox" class="form-check-input" id="agree" formControlName="agree">
  <label class="form-check-label" for="agree">
                          I agree to give some of my <span class="info-button text-muted"><a (click)="showModal()">personal information</a></span> to the partner that i worked with.
                        </label>
</div>

2 个答案:

答案 0 :(得分:1)

<div class="form-check">
  <input type="checkbox" class="form-check-input" id="agree" formControlName="agree">
  <label class="form-check-label" for="agree">
                          I agree to give some of my <span class="info-button text-muted"><a href="javascript:void(0)" (click)="showModal()">personal information</a></span> to the partner that i worked with.
                        </label>
</div>

通过添加javascript:void(0)更新您的html(标记):

<a href="javascript:void(0)" (click)="showModal()">personal information</a>

会的。

答案 1 :(得分:0)

使用:

event.preventDefault();
event.stopPropagation();

停止“ clck”事件冒泡。