0 0

jsp批量提交 怎么验证input空5

怎么验证这些input是否空啊
<input id="numid" name="appList[0].number" type="text" maxlength="2">
<input id="numid" name="appList[1].number" type="text" maxlength="2">
<input id="numid" name="appList[i].number" type="text" maxlength="2">
现在是在后台做的验证
但是我想在js验证
有什么好办法吗  求教...


另外请教ajaxsubmit怎么用啊
可能我查的不对,百度找的ajaxsubmit代码,都不能用
2014年5月30日 08:58
  • 大小: 46.4 KB

4个答案 按时间排序 按投票排序

0 0

采纳的答案

你坑爹吧,input的id和name属性的值是不是弄反了,id是唯一的大哥。
$("input[name='numid']") 获取所有的input标签,然后循环挨个判断下非空。

2014年5月30日 10:17
0 0

前端校验网上有一堆的校验框架,可以试试jquery-validation

2014年5月30日 15:29
0 0

页面中,标签的id是唯一的,不能重复,下面的代码已经测试通过
一般性的验证放在前端去做,减轻服务器的压力;服务端不验证或仅进行业务相关的验证


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="http://localhost:8080/sshdemo/static/js/jquery-1.7.2.min.js"></script>
        <meta name="viewport" content="width=device-width">
        <title>ajax提交</title>
        <script type="text/javascript">
            $(document).ready(function() {
                ajaxSubmit();
            });
            function ajaxSubmit() {
                $("#ajaxsubmit").click(function() {
                    var _numid1 = $("#numid1").val().trim();
                    if (_numid1.length === 0) {
                        alert("numid1不能为空");
                        return false;
                    }
                    var _numid2 = $("#numid2").val().trim();
                    if (_numid2.length === 0) {
                        alert("numid2不能为空");
                        return false;
                    }
                    var _numid3 = $("#numid3").val().trim();
                    if (_numid3.length === 0) {
                        alert("numid1不能为空");
                        return false;
                    }
                    $.ajax({
                        url: "http://localhost:8080/sshdemo/hello/ajax",
                        type: "post",
                        dataType: "json",
                        data: {
                            "numid1": _numid1,
                            "numid2": _numid2,
                            "numid3": _numid3
                        },
                        success: function() {
                            alert("success");
                        },
                        error: function() {
                            alert("error");
                        }
                    });
                });
            }

            function validation() {

            }
        </script>
    </head>
    <body>
        <form>
            <input id="numid1" name="appList[0].number" type="text" maxlength="2"/>
            <input id="numid2" name="appList[1].number" type="text" maxlength="2"/>
            <input id="numid3" name="appList[i].number" type="text" maxlength="2"/> 
            <input  id = "ajaxsubmit" type="button" value="提交"/>
        </form>
    </body>
</html>

2014年5月30日 11:07
0 0

function showRequest()
{
   //这边验证数据是否正确,返回false或者true
}

function submitForm(thisForm)
{
    var options = {
        target:            '#loginForm',
        beforeSubmit:    showRequest,
        success:        showResponse,
        error:            showError,
        
        url:               '',
        type:            'post',
        dataType:        'html',
        clearForm:        true,
        resetForm:        true,
        
        timeout:        3000
    };
    $(thisForm).ajaxSubmit(options);
  
}

2014年5月30日 09:31

相关推荐

Global site tag (gtag.js) - Google Analytics