HTML5 form required attribute. Set custom validation message?

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

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

14条回答
  •  梦毁少年i
    2020-11-22 01:47

    The easiest and cleanest way I've found is to use a data attribute to store your custom error. Test the node for validity and handle the error by using some custom html. enter image description here

    le javascript

    if(node.validity.patternMismatch)
            {
                message = node.dataset.patternError;
            }
    

    and some super HTML5

    
    

提交回复
热议问题