form表单的验证使用

版权声明:版权归wsc所有 https://blog.csdn.net/qq_37543808/article/details/88998118

大家是不是有这样的烦恼?

HTML5的input标签的验证效果得在form中提交是才触发。

如果我们只想把form表单内的数据作为ajax提交而不跳转,那我们怎么实现呢。

首先我们来阻止表单的提交跳转

<form action="gto.do" method="post" onsubmit="return false" id="form">
        <input type="email" name="email>
        <input type="number" min=11 max=11 name="phone>
        <button type="submit">提交</button>
</form>

document.getElementById("form").addEventListen("submit",function(){
   //你要做的事哦

})

猜你喜欢

转载自blog.csdn.net/qq_37543808/article/details/88998118