2016-07-25 15 views
1

我有我的代碼中的一些錯誤 這是我的錯誤:的爲標籤元素的屬性必須是指一個非隱藏表單控件

The for attribute of the label element must refer to a non-hidden form control.

而且MYD代碼:

<form action="/search"> 
 
    <span class="input input--hoshi search-wrapp main-page-open" style="display:block"> 
 
    <input class="input__field input__field--hoshi" type="text" id="search" name="keyword" placeholder="Search..."/> 
 
    <label class="input__label input__label--hoshi input__label--hoshi-color-2" for="input-5"> 
 
     <!--<span class="input__label-content input__label-content-hoshi">Search...</span>--> 
 
    </label> 
 
    <span class="icon-serch"></span> 
 
    </span> 
 
    <input id="search-btn" type="submit" style="display: none;"/> 
 
</form>

它有什麼問題?謝謝!

回答

0

驗證程序期望您的標籤的for字段指向包含它的輸入元素的id字段。在這裏,這意味着for="input-5"預計爲for="search",因爲<input>的ID是search

由於您期望用戶將輸入添加到此字段,您應該確保它們彼此鏈接。

2

標籤屬性必須包含輸入ID

<label for="foo">Foo:</label> 
<input id="foo"> 

要省略ID屬性都在一起,把輸入標籤

<label> 
    Foo: <input name="foo"> 
</label> 

還要注意,輸入不能隱藏<input type="hidden">,但它可以爲隱藏風格<input style="display:none">

相關問題