以下的代码 必须在点击value="检测标题是否已存在" 后才能知道 标题是否已存在
如何实现标题输入进去了就自动的检测呢?就如:我们到某网站去注册的时候,
在你输入用户名的时候,就自动的检测出:此用户名已经存在 或 此用户名可以注册。有请高手来指教啊 感激不尽啊<td>
<input type="text" name="info[title]" id="title" value="" size="50" class="inputtitle" onBlur="$.post('api/get_keywords.php?number=3&sid='+Math.random()*5, {data:$('#title').val()}, function(data){if(data) $('#keywords').val(data); })"/> <input type="button" value="检测标题是否已存在" onClick="$.post('?mod=phpcms&file=content&catid=12', { action : 'check_title', c_title:$('#title').val()}, function(data){ $('#t_msg').html(data); })">
<span style="color:'#ff0000'" id='t_msg'></span>
</td>
如何实现标题输入进去了就自动的检测呢?就如:我们到某网站去注册的时候,
在你输入用户名的时候,就自动的检测出:此用户名已经存在 或 此用户名可以注册。有请高手来指教啊 感激不尽啊<td>
<input type="text" name="info[title]" id="title" value="" size="50" class="inputtitle" onBlur="$.post('api/get_keywords.php?number=3&sid='+Math.random()*5, {data:$('#title').val()}, function(data){if(data) $('#keywords').val(data); })"/> <input type="button" value="检测标题是否已存在" onClick="$.post('?mod=phpcms&file=content&catid=12', { action : 'check_title', c_title:$('#title').val()}, function(data){ $('#t_msg').html(data); })">
<span style="color:'#ff0000'" id='t_msg'></span>
</td>
解决方案 »
- 在window下nginx+php,为什么php加载不到扩展dll
- syntax error, unexpected $end 怎么解决~麻烦高手帮我看一下~
- 请问php的<??>可以在html中嵌套吗?还是下面的程序有什么错误?
- 判断select的SQL语句执行后是否查询到结果的方法有那种?
- 汉字没有被截取,为何却显示乱码?
- 关于网页编码的疑问
- 在下求教如何在redhat8.0下安装GD库?
- 神奇的PHP 让我找不着北 floatval转 intval 变小
- 求助,在phpmyadmin中的sql语句总是插入不进去
- PHP插入的数据无法删除
- 怎样把输出的数据读到数据库中
- 登陆网站后台显示登录成功后 提示没有该权限
<td>
<input type="text" name="info[title]" id="title" value="" size="50" class="inputtitle" onBlur="check()"/>
</td><script>
function check(){
第一步:检验是否存在,返回能标识是否存在的值
第二步:如果存在,提示标题已存在,如alert(“标题已存在”)
}
</script>
//====JS文件=======
//实例化XMLHttpRequest对象
var ajax = false;
if(window.XMLHttpRequest)
{
ajax=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
try{
ajax=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e1)
{
try{
ajax=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e2){}
}
}
if(!ajax)
{
alert("some...");
}//检查是否为空 并给出提示
function check_username(username){
if(document.myform.username.value==""){
document.getElementById('chkuser').innerHTML=" <font color=red>用户名不能为空</font>";
document.myform.username.focus();
return false;
}// 检查用户名是否已经被注册过
if(ajax){
ajax.open("GET","reg.php?username="+username,true);
ajax.onreadystatechange=handle_check;
ajax.send(null);
}else{
document.getElementById('chkuser').innerHTML='ajax is error!';
}
}
function handle_check(){
if(ajax.readyState==4)
{
if(ajax.status==200)
{
document.getElementById('chkuser').innerHTML=ajax.responseText;
}
}
}
//=======HTML===============
<td><input name="username" type="text" id="username" size="20" onblur="check_username(this.form.username.value)"/>
<span id="chkuser"><font color=red>请输入用户名</font></span></td>
//=====PHP文件-reg.php==================
if(isset($_GET['username'])&&$_GET['username']!=""){
$username=trim($_GET['username']);
$sql="select * from `user_table` where `username`='".$username."'";
$query=mysql_query($sql); //好久没写 可能SQL函数有错误 我想这里你应该明白
$info=mysql_fetch_array($query);
if(is_array($info)){
echo "<font color='red'>It is reged</font>";
}else{
echo "<font color='red'>It is ab</font>"; }
}
//基本功能就完成了 别的自己无完善!