This question already has answers here:
How to show setCustomValidity message/tooltip without submit event

(8个答案)



HTML5/JS/jQuery: On invalid input, mark a different (arbitrary) element as invalid

(2个答案)


6年前关闭。




如何处理输入字段以设置setCustomValidity?这没用:

js fiddle
$('#numberinput').val("").setCustomValidity('The two email addresses must match.');

最佳答案

使用jQuery,您可以执行以下操作:

$('#numberinput').get(0).setCustomValidity('The two email addresses must match.');

并不是:
$('#numberinput').val("").setCustomValidity('The two email addresses must match.');

07-24 15:29