Javascript 如何检查表单中的所有输入字段是否为空?
如何检查表单中的所有输入字段(复选框、文本和收音机)以查看它们是否为空。然后用红色边框突出显示空的。谢谢。如果您使用jQuery,您可以执行以下操作:Javascript 如何检查表单中的所有输入字段是否为空?,javascript,html,css,Javascript,Html,Css,如何检查表单中的所有输入字段(复选框、文本和收音机)以查看它们是否为空。然后用红色边框突出显示空的。谢谢。如果您使用jQuery,您可以执行以下操作: (function($) { // After check for form submission $('form :input').each(function(i) { if( $(this).val() == '' ) { // Just remove the closest() method if you want
(function($) {
// After check for form submission
$('form :input').each(function(i) {
if( $(this).val() == '' ) {
// Just remove the closest() method if you want to give the
// actual input a border
$(this).closest('.parent-div').css({ 'border': '1px solid #c20000' });
}
});
})(jQuery);
可能重复的