Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我已经使用 keyup 检查了每个输入或使用不同的 js 文件更改事件。因此,用户可以在错误发生时看到他/她的错误。现在我想收集输入的所有验证信息并使点击事件提交按钮以启用或禁用提交。
我尝试为所有输入创建一个名为“isvalid”的自定义属性,并根据验证结果集“isvalid”为“true”或“false”。我的计划是检查所有 isvalid 值并禁用或启用提交按钮。但是我只能在同一个事件中获得更改的属性值,而不是在不同的 js 文件中。
您可以为每个输入指定一个特定的类名以表明它需要验证,并在您提交表单时循环它们:
$('.submit_button').click(function(event) { $('.required').each(function() { if (!this.value) { event.preventDefault(); alert('Please fill in all required fields'); } }); });