HTML5 form required attribute. Set custom validation message?

前端 未结 14 1900
你的背包
你的背包 2020-11-22 01:26

I\'ve got the following HTML5 form: http://jsfiddle.net/nfgfP/

14条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 01:39

    Try this one, its better and tested:

    HTML:

    JAVASCRIPT:

    function InvalidMsg(textbox) {
        if (textbox.value === '') {
            textbox.setCustomValidity('Required email address');
        } else if (textbox.validity.typeMismatch){
            textbox.setCustomValidity('please enter a valid email address');
        } else {
           textbox.setCustomValidity('');
        }
    
        return true;
    }
    

    Demo:

    http://jsfiddle.net/patelriki13/Sqq8e/

提交回复
热议问题