我希望默認值爲0,如果輸入大於0,則使用:valid
將輸入重新着色。難道我做錯了什麼? Google Chrome是否錯誤?或者HTML5規範?我想解決這個沒有JS。如何在輸入上使用模式[type =「number」]?
:valid {
background: green
}
<p>This should not be green, but it is:</p>
<input max="100" min="0" pattern="^[1-9]\d*$" type="number" value="0" />
<p>Works perfectly, if the type is changed to text:</p>
<input pattern="^[1-9]\d*$" type="text" value="0" />
我也沒有,所以我沒有看到數字輸入的理由不可能通過這種方式進行驗證。我也希望能夠出於其他原因使用模式,比如檢查數字是奇數還是偶數等。由於瀏覽器不像規範中建議的那樣工作,我會提交錯誤報告。 –