html - 如何在手风琴内插入超链接?
问题描述
我需要在手风琴内插入一堆蓝色超链接。因此,当我们单击标题时,出现的扩展区域将包含几行调用某个函数的行。
我尝试按照 Angular Material 网站上的示例进行操作: https ://stackblitz.com/angular/ybovddobxlj?file=app%2Fexpansion-overview-example.html
我已将expansion-overview-example.html 修改为以下内容:
<mat-accordion>
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
ALL FILES
</mat-panel-title>
</mat-expansion-panel-header>
<div> <!-- To put them on separate lines -->
<mat-form-field>
<label title="File 1" onclick="openFile1()"></label> <!-- THIS LINE BREAKS THE PAGE. HELP? -->
</mat-form-field>
</div>
<div> <!-- To put them on separate lines -->
<mat-form-field>
<label title="File 2" onclick="openFile2()"></label> <!-- THIS LINE BREAKS THE PAGE. HELP? -->
</mat-form-field>
</div>
</mat-expansion-panel>
</mat-accordion>
解决方案
首先,删除mat-form-field
,如果您只想在手风琴中添加一个简单的链接,则不需要它(这实际上是破坏您的代码的原因)。
只需添加一个p
带有(click)
事件处理程序的简单标签(它不在onclick
Angular 中)。这应该可以解决问题:
<div>
<p (click)="openFile1()">File 1</p>
</div>
如果您想label
改用,请像这样使用它:
<div>
<label (click)="openFile2()">File 2</label>
</div>
它应该有一个值,否则它是不可见的,你不能点击它。
这 是一个堆栈闪电战,您的示例代码已编辑以使其工作。
推荐阅读
- authentication - 任何开发人员都可以解码密码吗?
- javascript - 为什么我一直出错#NUM!第一次运行该功能后,但当我重新运行它时没有错误?
- sql - 无法加入两个临时表
- r - 未找到对象“MEDV”-> 但 MEDV 在数据集中
- python - 仅在 QTreeView 中 qstandard Item 的文本编辑时调用函数
- php - Nginx 到 php-fpm Docker 容器未连接
- node.js - 无法在 Google OAuth2.0 中对服务器到服务器应用程序进行身份验证
- postgresql - 我正在尝试从 localhost 服务器连接到 pgadmin
- jquery - 如何动态添加 id 并为每个复选框添加标签
- neo4j - Neo4J:返回给定键的每个值的最新数据节点