Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何检查表单中的所有输入字段是否为空?_Javascript_Html_Css - Fatal编程技术网

Javascript 如何检查表单中的所有输入字段是否为空?

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

如何检查表单中的所有输入字段(复选框、文本和收音机)以查看它们是否为空。然后用红色边框突出显示空的。谢谢。

如果您使用jQuery,您可以执行以下操作:

(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);
可能重复的