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

前端 未结 2 512
孤街浪徒
孤街浪徒 2021-01-12 23:13

I am trying to create one of those standard new password forms, where you type the new password once and then a second time to confirm. I would like it so that once you blur

2条回答
  •  失恋的感觉
    2021-01-12 23:32

    Try the below code. You are getting that error because jQuery returns an array of selected objects and since setCustomValidity is supported by native input elements and not jquery objects, you are seeing that error.

    $('#newpassword1, #newpassword2').each(function() {
        this.setCustomValidity(errorMessage)
    });
    

提交回复
热议问题