手机
当前位置:查字典教程网 >编程开发 >AJAX相关 >ajax应用
ajax应用
摘要:WebTools--AjaxVersion天气预报:IP地址查询:手机归属查询:chgBtnStyle();//针对不同的浏览器获取指定的i...

<DIV class=box id=top_bar>Web Tools--Ajax Version </DIV><BR>

<DIV>天气预报: <INPUT id=Weather size=17

value=北京> <INPUT onclick=getWeather() type=button value="提 交" name=submit> <SPAN

id=Disp_Weather></SPAN></DIV>

<DIV>IP地址查询: <INPUT id=Ip maxLength=17 size=17

value=127.0.0.1> <INPUT onclick=getIp() type=button value="提 交" name=submit> <SPAN

id=Disp_IPArea></SPAN></DIV>

<DIV>手机归属查询: <INPUT id=Mobile maxLength=15 size=17 value=13>

<INPUT onclick=getMobile() type=button value="提 交"> <SPAN

id=Disp_MobileArea></SPAN></DIV>

<SCRIPT language=JavaScript type=text/javascript>

chgBtnStyle();

</SCRIPT>

//针对不同的浏览器获取指定的id对象

function getObj(objID) {

return document.all ? document.all[objID] : document.getElementById(objID);

}

var req;

//使用xmlrequest对象

function createXHR() {

try {

req = new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e) {

try {

req = new ActiveXObject("Microsoft.XMLHTTP");

}

catch (E) {

req = false;

}

}

if (!req && typeof XMLHttpRequest != "undefined") {

req = new XMLHttpRequest();

}

}

function getWeather() {

createXHR();

req.open("GET", "weather.asp?City=" + getObj("Weather").value, true);

req.send();

req.onreadystatechange = handleStateChange1;

}

function handleStateChange1() {

if (req.readyState<4){getObj("Disp_Weather").innerText = "正在查询["+getObj("Weather").value+"]天气状况..."}

else if (req.readyState == 4 && req.status == 200) {

getObj("Disp_Weather").innerText = req.responseText;

} else {

getObj("Disp_Weather").innerText = "u67e5u8be2u8fc7u7a0bu51fau73b0u8fc7u7a0buff0cu8bf7u91cdu8bd5u6216u8054u7cfbu7ba1u7406u5458uff01";

}

}

function checkip() {

var ipArray, ip, j;

ip = getObj("Ip").value;

if (/[^d.]/.test(ip)) {

return false;

}

ipArray = ip.split(".");

if (ipArray.length != 4) {

return false;

}

for (var i = 0; i < 4; i++) {

if (ipArray[i].length == 0 || ipArray[i] > 255) {

return false;

}

}

return true;

}

function getIp() {

if (checkip()) {

createXHR();

req.open("GET", "IpSearch.asp?IP=" + getObj("Ip").value, true);

req.send();

req.onreadystatechange = handleStateChange;

} else {

getObj("Disp_IPArea").innerText = "u8fd4u56deu9519u8befuff1au4e0du662fu6b63u786eu7684ip";

}

}

function handleStateChange() {

if (req.readyState<4){getObj("Disp_IPArea").innerText = "正在查询ip["+getObj("Ip").value+"]..."}

else if (req.readyState == 4 && req.status == 200) {

getObj("Disp_IPArea").innerText = req.responseText;

} else {

getObj("Disp_IPArea").innerText = "u67e5u8be2u8fc7u7a0bu51fau73b0u9519u8befuff0cu8bf7u91cdu8bd5u6216u8054u7cfbu7ba1u7406u5458uff01";

}

}

function checkMobile() {

var sMobile = getObj("Mobile").value;

if (!(/^13[0-9]d{4,8}$/.test(sMobile))) {

return false;

}

return true;

}

function getMobile() {

if (checkMobile()) {

createXHR();

req.open("GET", "MobileSearch.asp?Mobile=" + getObj("Mobile").value, true);

req.send();

req.onreadystatechange = handleStateChange2;

} else {

getObj("Disp_MobileArea").innerText = "u8fd4u56deu9519u8befuff1au4e0du662fu5b8cu6574u768411u4f4du624bu673au53f7u6216u8005u6b63u786eu7684u624bu673au53f7u524du4e03u4f4d";

}

}

function handleStateChange2() {

if (req.readyState<4){getObj("Disp_MobileArea").innerText = "正在查询手机号码["+getObj("Mobile").value+"]..."}

else if (req.readyState == 4 && req.status == 200) {

getObj("Disp_MobileArea").innerText = req.responseText;

} else {

getObj("Disp_MobileArea").innerText = "u67e5u8be2u8fc7u7a0bu51fau73b0u9519u8befuff0cu8bf7u91cdu8bd5u6216u8054u7cfbu7ba1u7406u5458uff01";

}

}

function chgBtnStyle(){

var btn=document.getElementsByTagName("input")

for(var i=0;i<btn.length;i++){

if(btn[i].type=='button'){

btn[i].className="btnStyle";

}

}

}

【ajax应用】相关文章:

Ajax+asp应用实例 注册模块,表单提交

AJAX开发技术在PHP开发中的简单应用技巧

JavaScript学习总结之JS、AJAX应用

AJAX 用户注册时的应用实例

jquery $.ajax入门应用一

.NET2.0环境下的Ajax选型和应用(提供Demo源码下载)

ASP.NET MVC中的AJAX应用

ajax 文件上传应用简单实现

Ajax 无刷新在注册用户名时的应用的代码

jQuery ajax应用总结

精品推荐
分类导航