【问题标题】:HTML: Unable to reach a link using Tab keyHTML:无法使用 Tab 键访问链接
【发布时间】:2019-08-09 17:30:01
【问题描述】:

我有一个页面,其中有一个包含输入字段块的表单。还有一个按钮提供给“添加另一个”,它允许添加更多与上述相同的块。

只要页面上有多个输入字段块,用户就会看到一个“删除”链接,允许他们从视图中删除相应的块。

我的问题是,在按 Tab 键时,“删除”链接永远不会突出显示。焦点移动到下一个块元素。

我尝试过使用 Tab 索引,但由于 Tab 键不遵循顺序,因此未能解决问题。

<fieldset class="fieldset" id="fieldset-${receiptDetails.id}" style="width: 100%">
    <legend style="display: none;">Receipt Detail Section - ${receiptDetails.id}</legend>
    <label for="id" class="visually-hidden">Id: </label>
    <input type="text" name="id" id="id" style="display: none" value="${receiptDetails.id}">

    <div class="form-group">
        <label class="claim-label" for="nameAddressOfSupplier" id="name-address-supplier-label">
            [@spring.message "receipts-upload.supplier.name.address.label.text"/]
        </label>
        <textarea class="govuk-textarea" id="nameAddressOfSupplier-${receiptDetails.id}" name="nameAddressOfSupplier">${receiptDetails.nameAddressOfSupplier}</textarea>
    </div>

    <div class="form-group">
        <label class="claim-label" for="purchaseDetails" id="purchase-details-label">
            [@spring.message "receipts-upload.purchase.details.label.text"/]
        </label>
        <textarea class="govuk-textarea" id="purchaseDetails" name="purchaseDetails">${receiptDetails.purchaseDetails}</textarea>
    </div>

    <div class="custom-form-group">
        <label class="claim-label" for="amount" id="amount-label">
            [@spring.message "receipts-upload.amount.label.text"/]
        </label>
        <div class="currency-input">
            <div class="currency-input__denomination">£</div>
            <input class="currency-input__field text-input" data-component="date-check-length" data-length="9" type="text" id="amount" value="${receiptDetails.amount}" name="amount" style="display: inline"> [#if numberOfReceiptDetails == 1]
            <p class="remove-link visually-hidden" id="remove-link_${receiptDetails.id}" name="remove-link">
                <span class='googleAnalyticsRemove'>
                        <a id="remove-receipt-detail_${receiptDetails.id}" name="remove-receipt-detail"
                           class="action--secondary remove-receipt-detail" style="float: right">
                               [@spring.message "receipts-upload.remove.text"/]
                        </a>
                    </span>
            </p>
            [#else]
            <p class="remove-link" id="remove-link_${receiptDetails.id}" name="remove-link">
                <span class='googleAnalyticsRemove'>
                        <a id="remove-receipt-detail_${receiptDetails.id}" name="remove-receipt-detail"
                            class="action--secondary remove-receipt-detail" style="float: right">
                                [@spring.message "receipts-upload.remove.text"/]
                        </a>
                    </span>
            </p>
            [/#if]
        </div>
    </div>
</fieldset>

<p class="add-another-link" id="add-another-link">
    <a href="" id="add-another" class="action--secondary">
               [@spring.message "receipts-upload.add.another.text"/]
        </a>
</p>

当用户单击“添加另一个链接”时,另一个字段集将添加到视图中,每个字段集都有一个可见的“删除链接”。

我希望在按下 Tab 键时从“input#amount”到达每个字段集元素内的“remove-link”,但实际上按下 Tab 键会突出显示下一个字段集中包含的“textarea[name=nameAddressOfSupplier]”。

如有任何建议,我将不胜感激。

【问题讨论】:

    标签: javascript html


    【解决方案1】:

    如果你没有在&lt;a&gt;标签中使用href,tab键(tabindex)会跳过那个标签,

    如果添加tabindex="0",tab键会到达链接。

    请参考帖子:Why would an `a` tag need `tabindex=0`?

    【讨论】:

    • 所以我需要在&lt;a&gt; 标签中提供href 或提供tabindex="0"
    • 是的,我想是的
    猜你喜欢
    • 1970-01-01
    • 2019-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-19
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    相关资源
    最近更新 更多