2017-05-08 85 views
0

上得到一個輸入(複選框)工作之後無效,以顯示自定義消息時,它是無效的(未選中),但被示出的消息後,如果用戶檢查框訊息仍然顯示並被認爲無效。我認爲這與oninvalid有關,但不確定。輸入oninvalid自定義消息仍保持在選擇框

輸入代碼

什麼我得到的

<input style="width:15px; height:15px; cursor: pointer;" class="form-check-input" type="checkbox" onclick="setCustomValidity('')" oninvalid="this.setCustomValidity('Please review the legal agreement and check this box to proceed')" required>

圖片後首先得到錯誤信息,然後檢查箱子

error image `

+0

其中是'setCustomValidity'代碼上? – GibralterTop

+0

@GibralterTop的'setCustomValidity'方法只是分配消息無效,[文件](https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/setCustomValidity) –

+0

ahhhhhhh,由於 – GibralterTop

回答

0

這工作對我來說

  <input style="width:15px; height:15px; cursor: pointer;" name="legal" 
     class="form-check-input" type="checkbox" required id="legal" 
     onchange="this.setCustomValidity(validity.valueMissing ? 'Please review the legal agreement and check this box to proceed' : '');"> 

和控制器

document.getElementById("legal").setCustomValidity("Please review the legal agreement and check this box to proceed");