我試過標記的required
屬性。當用戶輸入空值時,瀏覽器應彈出警告Please fills out this field
。必需屬性在Firefox上不起作用
它在Chrome瀏覽器中正常工作,但是當我使用Firefox(版本53.0)時,彈出窗口似乎立即消失。這裏是我的測試代碼:
<!DOCTYPE html>
<html>
<head>
<title>Testing</title>
</head>
<body>
<form>
<input type="text" required />
<button type="submit">Submit</button>
</form>
</body>
</html>
你知道如何解決它嗎?如果不能解決,你能解釋爲什麼Firefox會這麼做嗎?
更新1:它適用於Windows上的Firefox。但它在Ubuntu(16.04)的Firefox上仍然不起作用。
嘗試required =「required」 –
看來我工作(火狐53)。不過,請注意,Firefox只顯示一個紅色的暈(用「box-shadow」實現),而不是Chrome和Opera顯示的彈出窗口。您可能會在您的樣式表中重寫「box-shadow」。 – Simone
也適合我。 – Lucky