jquery
<script>
function checkName(){
if( $("#account").val()){
$.post('__URL__/checkAccount/',{'account':$("#account").val()},function(data){
$("#checkNameAlert").html(data);
});
}else
{
$("#checkNameAlert").html('<font color="#FF0000">用户名不能为空。</font>');
}
}
</script>
action
public function checkAccount() {
$User = M("sms_user");
// 检测用户名是否冲突
$name = $_REQUEST['account'];
$result = $User->query("select * from sms_user where account='$name'");
if($result) {
echo "<font color=\"#FF0000\">账号存在请更换。</font>";
}else {
echo "<font color=\"#00FF00\">账号可使用。</font>";
}
}
//可修改为model 中识别。
tpl
<input name="account" type="text" id="account" οnblur="checkName();" maxlength="50"/> <span id="checkNameAlert" style="margin-left:20;"></span>