if(responseContext.indexOf("true")!=-1)是什么意思?

来源:百度知道 编辑:UC知道 时间:2024/06/23 20:33:14
使用Ajax技术来实现用户名是否可用中的
function processor(){
var responseContext;
if(xmlHttp.readyState==4){//如果响应完成
if(xmlHttp.status==200){//如果返回成功
responseContext = xmlHttp.responseText;
if(responseContext.indexOf("true")!=-1){
alert("恭喜您,该用户名有效!");
}
else{
alert("对不起,该名字已经被别人使用!");
}
}
}

if(responseContext.indexOf("true")!=-1)是什么意思?

是从服务器返回的值里面有"true"这个字符串.

indexOf的检查字符串中有没有指定的子字符串.并返回子字符出现在字符串中的索引.当不包含的时候.返回-1.

indexOf("true")!=-1就是说包含这个"true"子字符串.