<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!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=gb2312" />
<title>无标题文档</title>
</head><body>
<form onsubmit="return checkSame(this);" id="form1" name="form1" method="post" action="">
<table width="400" border="0" align="center">
<tr>
<td width="196" height="23" align="center">用户名</td>
<td width="194" align="center">密码</td>
</tr>
<% for i=1 to 3%>
</table>
<table width="400" border="0" align="center">
<tr>
<td align="center"><input type="text" name="abc<%=i%>" /></td>
<td align="center"><input type="text" name="cde<%=i%>" /></td>
</tr>
</table>
<%next %>
<table width="400" border="0" align="center">
<tr>
<td width="173"> </td>
<td width="217"><input type="submit" name="Submit" value="提交" /></td>
</tr>
</table>
</form><script>
// 默认所有表单内的元素都是 input ,且 type=text|password
function checkSame(frm){
for (var i = 0 ; i < frm.elements.length - 1 ; i ++){
for (var j = 0 ; j < frm.elements.length ; j ++){
if (i!=j)
{
if (frm.elements[i].value == frm.elements[j].value){
alert('表单元素"' + frm.elements[i].name + '"的值与"' + frm.elements[j].name + '"发生重复!');
frm.elements[j].focus();
return false; } }
}
}
window.open ("http://www.163.com") ;
}
</script></body>
</html>------------------------------------------------------------------------------------------------------我要的效果是:只要用户名重复就提示,而用户名与密码重复则不会提示。
上面的代码效果就是:用户名与密码重复也提示,就是这里不知怎样改了,请高手指点。谢!
<!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=gb2312" />
<title>无标题文档</title>
</head><body>
<form onsubmit="return checkSame(this);" id="form1" name="form1" method="post" action="">
<table width="400" border="0" align="center">
<tr>
<td width="196" height="23" align="center">用户名</td>
<td width="194" align="center">密码</td>
</tr>
<% for i=1 to 3%>
</table>
<table width="400" border="0" align="center">
<tr>
<td align="center"><input type="text" name="abc<%=i%>" /></td>
<td align="center"><input type="text" name="cde<%=i%>" /></td>
</tr>
</table>
<%next %>
<table width="400" border="0" align="center">
<tr>
<td width="173"> </td>
<td width="217"><input type="submit" name="Submit" value="提交" /></td>
</tr>
</table>
</form><script>
// 默认所有表单内的元素都是 input ,且 type=text|password
function checkSame(frm){
for (var i = 0 ; i < frm.elements.length - 1 ; i ++){
for (var j = 0 ; j < frm.elements.length ; j ++){
if (i!=j)
{
if (frm.elements[i].value == frm.elements[j].value){
alert('表单元素"' + frm.elements[i].name + '"的值与"' + frm.elements[j].name + '"发生重复!');
frm.elements[j].focus();
return false; } }
}
}
window.open ("http://www.163.com") ;
}
</script></body>
</html>------------------------------------------------------------------------------------------------------我要的效果是:只要用户名重复就提示,而用户名与密码重复则不会提示。
上面的代码效果就是:用户名与密码重复也提示,就是这里不知怎样改了,请高手指点。谢!
for (var i=0; i<this.length; i++)
action(this[i], i, this);
};
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
// 默认所有表单内的元素都是 input ,且 type=text|password
function checkSame(frm) {
var map = {};
with ([]) {
forEach.call(frm.elements, function(e) { if (/^abc\d+$/.test(e.name)) push(e); });
forEach(function(e) { e.value = e.value.trim(); });
try {
forEach(function(input) {
if (input.value!="") return;
input.focus();
throw new Error(-1, input.name + "不能为空值!");
});
forEach(function(input, i) {
if (map[input.value]) {
input.focus();
throw new Error(-1, map[input.value].name + " 与 " + input.name + " 重复!");
}
map[input.value] = input;
});
} catch(e) {
alert(e.message);
return false;
}
}
window.open ("http://www.163.com");
}