hgc-ghc
Good Good Study!!! Day Day Up!!!
posts - 40,comments - 3,trackbacks - 0
<script type="text/javascript">
//看不清后 获取验证码的方法 
function idenfunc()
{
document.getElementById("idenimage").value="";//$("#input06").val("");
document.getElementById("idenimage").setAttribute("src","createMa.jsp?temp="+new Date());
//$("#idenimage").attr("src","createMa.jsp?temp="+new Date());
}
function createXhr() {
var httprequest = false;
if (window.XMLHttpRequest) { // if Mozilla, Safari etc
httprequest = new XMLHttpRequest();
if (httprequest.overrideMimeType)
httprequest.overrideMimeType('text/xml')
} else if (window.ActiveXObject) { // if IE
try {
httprequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
httprequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
}
}
}
return httprequest;
}
var xhr;//声明全局变量 用来表示XMLHttpRequest对象 

//验证码的 验证 
function validateCodeCheck(){
xhr = createXhr(); //1.创建XmlHttpRequest对象
var vc = document.getElementById("validate_code").value;
var u=trim(vc);
if(u==""){
document.getElementById("message_vc").innerHTML = 
"<strong><font face='楷体' size='3' color='red'>请输入验证码</font></strong>";
document.getElementById("message_vc").focus();
return;
}
var _vc = encodeURI(encodeURI(u));
var myUrl = "<%=request.getContextPath()%>/CheckCreateMaServlet?vc=" + _vc;
//xhr.open("get","CheckIdServlet?id="+_userId+"&now="+mydate,true);
xhr.open("get", convertUrl(myUrl), true); //2.调用open()方法打开一个新的请求
xhr.send(); //3.调用send()方法发送请求到服务器端
xhr.onreadystatechange = myCreateMaCheck; //4.编写用于处理 readyState 属性值发生改变的方
}
function myCreateMaCheck() {
if (xhr.readyState == 4 && xhr.status == 200) { //当readyState的属性为值 为4时表示HTTP 响应已经完全接收
var returnData = xhr.responseText; //当前请求的http状态码值200时表示成功
//alert(returnData); //这是双重保险 
if(returnData=="no"){
document.getElementById("validate_code").value="";
document.getElementById("validate_code").focus();
document.getElementById("message_vc").innerHTML = 
"<strong><font face='楷体' size='3' color='red'>验证码有误</font></strong>";
}else{
document.getElementById("message_vc").innerHTML =
"<strong><font face='楷体' size='3' color='green'></font></strong>";
}
}
}

</script>
<body>
    <li>
                 <label class="lable-t">验证码:</label>
                 <input type="text" name="validate_code" id="validate_code" size="10" 
                  maxlength="4" style="height:25px; vertical-align:middle" 
                  value=""   onblur="validateCodeCheck();"/>
                  &nbsp;&nbsp;
                  <label id="message_vc"></label>
                  <img id="idenimage" src="createMa.jsp" alt="" />
                  <a href="#" onclick="idenfunc();" class="blue">看不清</a>
               </li>
</body>
posted on 2012-08-29 12:12 宏才 阅读(149) 评论(0)  编辑  收藏 所属分类: jsp