现在的位置: 首页 > 综合 > 正文

判断多个文本框输入的数据是不是有重复(原创)

2013年10月15日 ⁄ 综合 ⁄ 共 695字 ⁄ 字号 评论关闭

此代码是根据CSDN梅花雪的去掉数组中重复的元素扩展的

<form name=form1>
<input name=a123>
<input name=b123>
<input name=c123>
<input name=d123>
<input name=e123>
<input name=f123 type=button onclick=check()>
</form>
<SCRIPT LANGUAGE="JavaScript">
<!--
Array.prototype.unique = function()
{
  var a = {}; for(var i=0; i<this.length; i++)
  {
    if(typeof a[this[i]] == "undefined")
      a[this[i]] = 1;
  }
  this.length = 0;
  for(var i in a)
    this[this.length] = i;
  return this;
}
function check()
{
 var ArrText = [document.form1.a123.value,document.form1.b123.value,document.form1.c123.value,document.form1.d123.value,document.form1.e123.value];
 OldArr=ArrText.length;
 NewArr=ArrText.unique().length;
 if(OldArr==NewArr)
 {
  alert("无重复记录");
 }
 else
 {
  alert("有重复记录");
 }
}
//-->
</SCRIPT>

抱歉!评论已关闭.