Missing something very elementary here, I have a basic form im testing on that I want to check if a field is empty :

在这里缺少一些非常基本的东西,我有一个基本的表单即时测试,我想检查字段是否为空:

    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/Logistics.asp" -->
<!DOCTYPE html>
<html>
<head>
  <meta "http-equiv="X-UA-Compatible" content="IE=edge"">
  <title>XXXXXXXXXXXXXXXX</title>
<script src="img/scripts/jquery-1.11.2.min.js"></script>
<script>
$(window).load(function(){
var fields  = $(":input").serializeArray();
$.each(fields,function(i,e){
    if(e.value === ""){
        $( "span" ).text( "Not valid!" ).show().fadeOut( 1000 );  
        event.preventDefault();
        }
    });
});
</script>
</head>
<body>
<form id="form">
    <input type="text" name="1" id="in1" value="hi">
    <input type="text" name="2" id="in2" value="asdf"/>
    <input type="text" name="3"id="in3" value="bye">
    <span></span>
</form>
</body>
</html>

Is able to work, however I would like to know which field in particular is blank and add either a red outline or text inside indicating it is required. Any thoughts?

能够工作,但我想知道哪个字段特别是空白,并在内部添加红色轮廓或文本,表明它是必需的。有什么想法吗?

JFiddle Here

3 个解决方案

#1


$('#form input').each(function(){
    if($(this).val() == ""){
         alert('this field is empty');
        $(this).css('border','1px solid red');
    }else{
        alert($(this).val());
    }
});

JSFIDDLE

更多相关文章

  1. 用于转换单位的HTML和JavaScript表单
  2. jQuery表单验证Validata
  3. 在Javascript中将下拉字段乘以文本字段
  4. Javascript实现统一的表单验证
  5. 【JavaScript】案例一:使用JS完成注册页面表单校验
  6. 如何检查不包含提交按钮的HTML5表单的有效性?
  7. 如何在Python Django中附加数组字段
  8. flask-admin 新增功能关联两张表,关联的表中的字段显示出来是对象
  9. Python Flask WTForms:如何在视图中动态禁用字段?

随机推荐

  1. XML(4)XDocument和XmlDocument搜索指定的节
  2. dom4j 操作xml文件(全)
  3. XML(3)XDocument与XmlDocument递归读取xml
  4. 第17天 Android(安卓)Touch事件学习 4 获
  5. XML(2)通过XmlDocument与XDocument方式写入
  6. Linux Deploy:在Android上部署Linux
  7. 走近XML(1)
  8. android 处理生命周期事件
  9. XML卷之实战锦囊(5):结构树图
  10. Android(安卓)Wifi模块学习