日期:2014-05-16  浏览次数:20311 次

jquery 数组循环验证 IE6提示不支持,其他浏览器都可以通过。
HTML code



<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
<script language="javascript" type="text/javascript">
    function query() {
        var waybills = document.getElementById("waybills");
        if(waybills.value == '') {
            alert('请输入要查询的快件单号');
            $("#waybills").val('最多输入20个运单号码,以Enter隔开。');
            document.form.waybills.focus();
            return false;
        }
        var patten = /^\d{13}$/;
        var listI = document.form.waybills.value.split("\r\n");
        var listF = document.form.waybills.value.split("\n");
        var list = null;
        if(listI.length > listF.length) {
            list = listI;
        } else {
            list = listF;
        }
        if(list.length >= 21) {
            alert('一次最多只能查询20个快件单号');
            document.form.waybills.focus();
            return false;
        }
        for( i = 0; i < list.length; i++) {
            var len = i + 1;
            if(list[i].trim().length != 13 && list[i].trim().length != 0) {//ie6 提示: 行28,字符4, 错误:对象不支持此属性或方法
                var msg = '输入的第%count%个快件单号长度必须等于13!';
                alert(msg.replace('%count%', len));
                document.form.waybills.focus();
                return false;
            }
            if(!patten.test(list[i].trim())) {
                var msg = '输入的第%count%个快件单号必须是数字,且为半角输入法!';
                alert(msg.replace('%count%', len));
                document.form.waybills.focus();
                return false;
            }
        }
        /*
         if (!checkIsNotEmpty(document.form.verifyImg.value)){
         alert('请输入验证码!');
         document.form.verifyImg.focus();
         return false;
         }*/

        $("#form").submit()

        //return false;

    }


    $(document).ready(function() {
        var waybills = document.getElementById("waybills");
        $("#waybills").focus(function() {
            var str = '最多输入20个运单号码,以Enter隔开。';
            if(str != waybills.value) {
                $(this).val('')
            }
        })

        $("#waybills").blur(function() {
            if(waybills.value == '') {
                $("#waybills").val('最多输入20个运单号码,以Enter隔开。');
            }
        })
        $("#waybills").val('最多输入20个运单号码,以Enter隔开。');
    })
</script>
<div class="content">
    <h2 class="title">快件追踪</h2>

    <div class="tp_qq_list">
        <h5>Query</h5>
        <form action="__URL__/check" method="post" id="form" name="form">
            <table id="querytb" width="598" border="0" cellspacing="0" cellpadding="0" >
                <tr>
                    <td valign="top" width="598">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td valign="top" width="590">
                            <table width="100%" border="0" cellspacing="3" cellpadding="0">
                                <tr>
                                    <td class="tdtext-right-color1">
                                    <div class="divtext-center">
                                        输入单号
                                    </div></td