加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

AJAX showHint()函数

发布时间:2020-12-16 00:39:38 所属栏目:百科 来源:网络整理
导读:data.php ?php header("Content-type: text/html; charset=utf-8"); $val = $_GET['q'];$regular = '/^[A-Z]/';if (!preg_match($regular,$val)) {echo '用户名不合法';} ? htmlheadscript type="text/javascript"function showHint(str){var xmlhttp;if (st

data.php

<?php 
header("Content-type: text/html; charset=utf-8"); 
$val = $_GET['q'];
$regular = '/^[A-Z]/';
if (!preg_match($regular,$val)) {
	echo '用户名不合法';
}

 ?>


<html>
<head>
<script type="text/javascript">
function showHint(str)
{
var xmlhttp;
if (str.length==0)
  { 
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+,Firefox,Chrome,Opera,Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6,IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","data.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<h3>请在下面的输入框中键入字母(A - Z):</h3>
<form action=""> 
<p>姓氏:<input type="text" id="txt1" onkeyup="showHint(this.value)" /><span id="txtHint"></span></p>
<input type="reset">
</form>
</body>
</html>

效果图:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读