weatherforecast.js

来自「买书附带的光盘资料Foundations_Of_Ajax中文版教程及源代码。 」· JavaScript 代码 · 共 48 行

JS
48
字号
var weatherForecastIntervalID = 0;function updateWeatherForecast() {    var ajaxRequest = new AjaxRequest("UpdateWeatherForecast");    ajaxRequest.addFormElementsById("forecastZipCode");    ajaxRequest.sendRequest();}function handleZipCodeChange() {    var zipCode = document.getElementById("forecastZipCode").value;    if(isValidZipCode(zipCode)) {        updateWeatherForecast();        startWeatherUpdateInterval();    }    else {        if(weatherForecastIntervalID != 0) {            window.clearInterval(weatherForecastIntervalID);            weatherForecastIntervalID = 0;        }    }}function startWeatherUpdateInterval() {    weatherForecastIntervalID = window.setInterval("updateWeatherForecast()", 300000);}function isValidZipCode(zip) {    if(zip.length == 5 && isAllDigits(zip)) {        return true;    }    return false;}function isAllDigits(argvalue) {    argvalue = argvalue.toString();    var validChars = "0123456789";    var startFrom = 0;    for (var n = startFrom; n < argvalue.length; n++) {        if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) {            return false;        }    }    return true;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?