日期:2014-05-16 浏览次数:20434 次
<input type='text' name='keywords' id='keywords' class='txt' value="123" onblur="w(this.id,this.value);"/>
function w(i,v){
var s = $.inArray(v,keyarr);
if(s !=-1){
alert('不能重复添加标签');
$("#"+i).focus();
return;
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<title>无标题文档</title>
<script type="text/javascript">
function checkUsername(ele){
if(document.getElementById("username").value==""){
document.getElementById("username").setAttribute('placeholder',"不能为空");
//fix mozilla element focus bug
setTimeout(function(){
ele.focus();
});
}
}
function checkPsw(){
if(document.getElementById("psw1").value != document.getElementById("psw2").value){
document.getElementById("checkpassword").innerHTML="两次输入不一致";
document.getElementById("psw2").focus();
}
}
</script>
</head>
<body>
<div>
<form name="f2">
username:<input type="text" name="username" id="username" tabindex="1" onblur="checkUsername(this)"/><br/>
password1:<input type="password" id="psw1" tabindex="2" /><br/>
password2:<input type="password" name="psw2" id="psw2" tabindex="3" onkeypress="checkPsw()"/><br/>