【问题标题】:Avoid checkbox clicked when label has been clicked避免单击标签时单击复选框
【发布时间】:2019-04-14 23:57:16
【问题描述】:

我有一个这样的复选框和标签。这里的问题是我无法单击href,因为整个部分作为一个单元工作。即当我单击标签时,它会触发复选框。那么我怎样才能分离或避免这种行为呢?即我需要点击超链接。

  <ion-item>
    <ion-label class="long-text">I accept the Terms & Conditions and the Privacy Policy found
      <a href="#" (click)="goToPrivacyPolicy()">here</a></ion-label>
    <ion-checkbox [(ngModel)]="terms" slot="start"></ion-checkbox>
  </ion-item>

用户界面

试过这个:但还没有运气?

.ts

  goToPrivacyPolicy(event) {
    event.stopPropagation(); //or event.preventDefault()
    this.iab.create(environment.privacyPolicy);
  }

html

<ion-item>
    <ion-label class="long-text">I accept the Terms & Conditions and the Privacy Policy found
      <a href="#" (click)="goToPrivacyPolicy($event)">here</a></ion-label>
    <ion-checkbox [(ngModel)]="terms" slot="start"></ion-checkbox>
  </ion-item>

【问题讨论】:

标签: html angular ionic-framework ionic4


【解决方案1】:

检查 WORKING STACKBLITZ

<ion-item text-wrap>
 <ion-row>
    <ion-col col-2 no-padding no-margin>
      <ion-item no-padding no-margin no-lines>
        <ion-checkbox [(ngModel)]="agreed"></ion-checkbox>
      </ion-item>
    </ion-col>
    <ion-col col-10 no-padding no-margin>
      <ion-item no-padding no-margin no-lines>
        Agree to <a target="_blank" href="http://www.terms-of-service.com">Terms of Service</a> and <a target="_blank" href="http://www.privacy-policy.com">Privacy Policy</a>. found  <a href="#" (click)="goToPrivacyPolicy($event)">here</a>
      </ion-item>
    </ion-col>
  </ion-row>
</ion-item>

【讨论】:

  • 没有区别。与我的帖子相同的行为。
  • 是的,我知道这种行为。实际上,这是一个偶然的用例。即我使用ion-grid 开发了动态复选框列表,但它没有这种行为。但是当前页面使用&lt;ion-item&gt; 开发。因此,使用网格重做需要时间。无论如何,我已经为此找到了一个技巧。我稍后再放。谢谢和 +1。
猜你喜欢
  • 1970-01-01
  • 2017-12-25
  • 2017-12-03
  • 1970-01-01
  • 2022-10-16
  • 2016-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多