我不能让这个脚本在IE中工作,我做错了什么

时间:2013-07-18 03:30:54

标签: javascript internet-explorer

我想使用这个脚本,但我发现它不能在Internet Explorer中工作。我将在所有其他测试的浏览器中工作。 感谢

<form name = "myform">
    <b>To find if we service your area,<br> Please enter your postcode</b><br> <input type = "text" name = "zip" size = "4" maxlength = "4" onchange = "checkZip()">
</form>

<script type = "text/javascript">
    function checkZip() {

        var z = document.myform.zip;
        var zv = z.value;
        if (!/^\d{4}$/.test(zv)) {
            alert ("Please enter a valid Postcode");
            document.myform.zip.value = "";
            myfield = z;  // note myfield must be a global variable
            setTimeout('myfield.focus(); myfield.select();' , 10);  // to fix bug in Firefox
            return false;
        }

        var codes = [4000,4005,4006,4007,4008,4009,4010,4011,4012,4013,4014,4030,4051,4059,4064,
                     4065,4066,4075,4101,4102,4103,4104,4105,4106,4107,4108,4109,4110,4111,4112,
                     4113,4114,4115,4116,4117,4119,4120,4121,4122,4123,4127,4128,4151,4152,4153,
                     4154,4155,4156,4157,4158,4159,4160,4161,4163,4164,4169,4170,4171,4172,4173,
                     4174,4178,4179];
        // add as many zip codes as you like, separated by commas (no comma at the end)
        var found = false;
        for (var i=0; i<codes.length; i++) {
            if (zv == codes[i]) {
                found = true;
                break;
            }
        }

        if (!found) {
            alert ("The Post Code " + zv + " is not in our database, Please call 1300 736 979 to check and see if we can help you.");
            document.myform.zip.value = "";
            return false;
        }
        else {
            alert ("Yes, that Post Code is covered by our business");
        }
    }

</script>

0 个答案:

没有答案