1
、
Ajax
技术实现用户名检查原理
填入用户名-触发控件-获得填写内容-ajax传递-查询数据库-返回结果-dom反应到页面
2、学习HTML
的几种触发
onblur 事件会在对象失去焦点时发生。
onchange 事件会在域的内容改变时发生。
onclick 事件会在对象被点击时发生。
onfocus 事件在对象获得焦点时发生。
onkeydown 事件会在用户按下一个键盘按键时发生。
onkeypress 事件会在键盘按键被按下并释放一个键时发生。
onkeyup 事件会在键盘按键被松开时发生。
onmousedown 事件会在鼠标按键被按下时发生。
onmousemove 事件会在鼠标指针移动时发生。
onmouseout 事件会在鼠标指针移出指定的对象时发生。
onmouseup 事件会在鼠标按键被松开时发生。
3
、如何获取表单中的数据内容
<form name="myform"
…
<input name=user type=text value="">
</form>
对应js的code
document
.myform.user.value
关键代码:
<?php
include_once ('global.php');
if($_GET[id]){
sleep(1);
}
$sql="select * from `h_admin` where username = '$_GET[id]'";
$q=mysql_query($sql);
if(is_array(mysql_fetch_row($q))){
echo "1111";
}else{
echo "222";
}
?>
include_once ('global.php');
if($_GET[id]){
sleep(1);
}
$sql="select * from `h_admin` where username = '$_GET[id]'";
$q=mysql_query($sql);
if(is_array(mysql_fetch_row($q))){
echo "1111";
}else{
echo "222";
}
?>
以上判断用户名不存在就用ajax反映到页面
var xmlHttp;
//判断浏览器类型,ie和其他浏览器不同,要用active
function S_xmlhttprequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
}else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function funphp100(name){
var f=document.myform.user.value;
alert(f);
S_xmlhttprequest();
xmlHttp.open("GET","for.php?id="+f,true);
xmlHttp.onreadystatechange = byphp;
xmlHttp.send(null);
}
function byphp(){
if(xmlHttp.readyState==1){
document.getElementById('php100').innerHTML = "<img src='loading.gif'>";
}
if(xmlHttp.readyState==4){
var byphp100 = xmlHttp.responseText;
//这里php100和外面对应
document.getElementById('php100').innerHTML = byphp100;
}
}
//判断浏览器类型,ie和其他浏览器不同,要用active
function S_xmlhttprequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
}else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function funphp100(name){
var f=document.myform.user.value;
alert(f);
S_xmlhttprequest();
xmlHttp.open("GET","for.php?id="+f,true);
xmlHttp.onreadystatechange = byphp;
xmlHttp.send(null);
}
function byphp(){
if(xmlHttp.readyState==1){
document.getElementById('php100').innerHTML = "<img src='loading.gif'>";
}
if(xmlHttp.readyState==4){
var byphp100 = xmlHttp.responseText;
//这里php100和外面对应
document.getElementById('php100').innerHTML = byphp100;
}
}
以上关键在于var f=document.myform.user.value;
alert(f);
S_xmlhttprequest();
alert(f);
S_xmlhttprequest();
xmlHttp.open("GET","for.php?id="+f,true);
获取myform表单的user字段的值,然后弹出提示,传递f值到for.php中进行判断