简体   繁体   English

HTML<label>标签/元素无法识别输入元素的“id”属性</label>

[英]HTML <label> tag/element not recognizing "id" attribute of input element

I am writing an Angular application which uses ASP.Net Core as a backend, and bootstrap 4 and ngx-bootstrap for styling.我正在编写一个 Angular 应用程序,它使用 ASP.Net Core 作为后端,并使用 bootstrap 4 和 ngx-bootstrap 进行样式设置。

For some reason on all my HTML <label> tags (in every component/html file AND even though I have ID and Name attributes that match the "for" attribute of the <label> tag), the ID's are not found or recognized.出于某种原因,在我所有的 HTML <label>标签上(在每个组件/html 文件中,即使我的 ID 和 Name 属性与<label>标签的“for”属性匹配),也找不到或无法识别 ID。 I verified this by running the HTML through chrome dev tools lighthouse audit.我通过 Chrome 开发工具灯塔审计运行 HTML 来验证这一点。 Here is a sample of the code:下面是代码示例:

<div class="modal-header">
    <h4 class="fa-pull-left modal-title" id="modalTitle">{{title}}</h4>
</div>
<div class="modal-body" id="modalBody">
    <form id="modalForm">
        <div class="form-group">
            <label for="swName">Name</label>
            <input id="swName" name="swName" [(ngModel)]="switchman.Name" class="form-control" type="text" />
        </div>
        <div class="form-group">
            <label for="eid">EID</label>
            <input [(ngModel)]="switchman.Eid" class="form-control" id="eid" name="eid" type="text" />
        </div>
        <div class="form-group">
            <label for="homeOffice">Home Office</label>
            <input [(ngModel)]="switchman.HomeOffice" class="form-control" id="homeOffice" name="homeOffice" type="text" />
        </div>
<div class="modal-footer">
    <button (click)="accept()" class="btn btn-success mr-auto" type="button">
        Submit
    </button>
    <button (click)="reject()" class="btn btn-danger" type="button">
        Cancel
    </button>
</div>

In this section for example:在本节中,例如:

<form id="modalForm">
        <div class="form-group">
            <label for="swName">Name</label>
            <input id="swName" name="swName" [(ngModel)]="switchman.Name" class="form-control" type="text" />
        </div>

The <input> attribute of id="swName matches the for="swName" attribute of the <label> tag, but it isn't being applied at all, as if the id="swName" does not exist. id="swName<input>属性与<label>标签的for="swName"属性匹配,但它根本没有被应用,就好像id="swName"不存在一样。

How do I get the label to recongize the ID of the input tag?如何获取标签以识别输入标签的 ID?

This actually turned out to be an issue with Resharper not correctly seeing the ID/For relationship.这实际上是 Resharper 无法正确查看 ID/For 关系的问题。 After further testing using Chrome Dev Tools and Lighthouse, I realized that I did have a few other unrelated ID tags that were truly unresolved.在使用 Chrome Dev Tools 和 Lighthouse 进一步测试后,我意识到我确实有一些其他不相关的 ID 标签真正未解决。

Once I resolved these, the errors in Lighthouse went away, but my IDE still showed errors.一旦我解决了这些问题,Lighthouse 中的错误就消失了,但我的 IDE 仍然显示错误。 I have submitted a ticket to the JetBrains/ReSharper team.我已向 JetBrains/ReSharper 团队提交了一张票。 Screenshots attached.附上截图。

IDE: Visual Studio Enterprise 2019 16.5.1 IDE:Visual Studio Enterprise 2019 16.5.1

ReSharper: 2020.1 EAP 5 ReSharper:2020.1 EAP 5

OS: Win 10操作系统:Win 10

Link to issue: https://youtrack.jetbrains.com/issue/RSRP-478855问题链接: https : //youtrack.jetbrains.com/issue/RSRP-478855

UPDATE: JetBrains/ReSharper were able to recreate the issue and confirm that this is a bug that will be fixed in a future release.更新:JetBrains/ReSharper 能够重现该问题并确认这是一个将在未来版本中修复的错误。

Screens:屏幕:

未解决

未解决2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM