<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<input type="button" value="检查重复的行及索引号" onclick="Test()">
<div style="width:500px">
<div id="show" style="float:left"></div>
<div id="prin"></div>
</div>
<script type=text/javascript>
(function(){
var i = 0, str = '<table id="tab" width=300px>';
while (++i < 3001)
str += '<tr bgColor="#FFFFFF">\
<td><input type="text" style="width:100%" id="Text41" readonly ></td>\
<td><input type="text" style="width:100%" value='+ Math.round(30000*Math.random()) +' name="mc'+i+'" id="Text42"></td></tr>';
str += '</table>';
document.getElementById("show").innerHTML = str;
})();function Test(){
var str = "重复的行索引号<br>", hash = {}, arr = [], t = new Date,list=[];
var obj = document.getElementById("tab").getElementsByTagName("input");
for(var i = 0; !!obj[i]; i ++) i % 2 != 0 && (!!hash[obj[i].value] ? arr.push(i) : (hash[obj[i].value] = "@"));
alert("这6000行中3000个MC文本框有"+arr.length+"行重复,检测耗时" + [new Date - t] + "毫秒");
for(var j = 0; !!arr[j]; j ++)
str += [(arr[j] - 1) >>> 1] + "<br>";
document.getElementById("prin").innerHTML = str;
}
</script>1、这段是检查重复的行,和提示重复的行;现在需要把不重复的写入list=[]里,应该把list.push(obj[i].value)加到上面的什么地方?
2、帮忙解释一下(!!hash[obj[i].value] ? arr.push(i) : (hash[obj[i].value] = "@"))
<input type="button" value="检查重复的行及索引号" onclick="Test()">
<div style="width:500px">
<div id="show" style="float:left"></div>
<div id="prin"></div>
</div>
<script type=text/javascript>
(function(){
var i = 0, str = '<table id="tab" width=300px>';
while (++i < 3001)
str += '<tr bgColor="#FFFFFF">\
<td><input type="text" style="width:100%" id="Text41" readonly ></td>\
<td><input type="text" style="width:100%" value='+ Math.round(30000*Math.random()) +' name="mc'+i+'" id="Text42"></td></tr>';
str += '</table>';
document.getElementById("show").innerHTML = str;
})();function Test(){
var str = "重复的行索引号<br>", hash = {}, arr = [], t = new Date,list=[];
var obj = document.getElementById("tab").getElementsByTagName("input");
for(var i = 0; !!obj[i]; i ++) i % 2 != 0 && (!!hash[obj[i].value] ? arr.push(i) : (hash[obj[i].value] = "@"));
alert("这6000行中3000个MC文本框有"+arr.length+"行重复,检测耗时" + [new Date - t] + "毫秒");
for(var j = 0; !!arr[j]; j ++)
str += [(arr[j] - 1) >>> 1] + "<br>";
document.getElementById("prin").innerHTML = str;
}
</script>1、这段是检查重复的行,和提示重复的行;现在需要把不重复的写入list=[]里,应该把list.push(obj[i].value)加到上面的什么地方?
2、帮忙解释一下(!!hash[obj[i].value] ? arr.push(i) : (hash[obj[i].value] = "@"))
2。使用sort方法排序
3。从第一个循环遇到重复的删除
2、帮忙解释一下(!!hash[obj[i].value] ? arr.push(i) : (hash[obj[i].value] = "@"))的意思谢谢
<style>
#conts{width:600px}
#conts div{float:left;margin:10px}
</style>
<input type="button" value="检查重复的行及索引号" onclick="Test()">
<div id="conts">
<div id="show"></div>
<div id="prin"></div>
<div id="prnt"></div>
</div>
<script type=text/javascript>
(function(){
var i = 0, str = '<table id="tab" width=300px>';
while (++i < 3001)
str += '<tr bgColor="#FFFFFF">\
<td><input type="text" style="width:100%" id="Text41" readonly ></td>\
<td><input type="text" style="width:100%" value='+ Math.round(30000*Math.random()) +' name="mc'+i+'" id="Text42"></td></tr>';
str += '</table>';
document.getElementById("show").innerHTML = str;
})();function Test(){
var str = "重复的行索引号<br>", srr = "清除重复后数据<br>", hash = {}, arr = [], t = new Date, list=[];
var obj = document.getElementById("tab").getElementsByTagName("input"); for(var i = 0; !!obj[i]; i ++) i & 1 != 0 && (!!hash[obj[i].value] ? arr.push(i) : (hash[obj[i].value] = "@"));
alert("这6000行列3000个MC文本框中\n有"+arr.length+"行数据重复,\n未重复的有"+[obj.length-arr.length]+"行\n检测耗时" + [new Date - t] + "毫秒"); for(var j = 0; !!arr[j]; j ++)
str += [(arr[j] - 1) >>> 1] + "<br>";
document.getElementById("prin").innerHTML = str; for(var num in hash)//直接调用hash,里面装的就是清除重复后剩下来的数据
list[list.length] = num,//按你的要求把不重复数据写入list数组
srr += num + "<br>";
alert("list数组元素为\n"+list.join("\n"));//alert list数组元素
document.getElementById("prnt").innerHTML = srr;
}
</script>
BTW:还能看到自己以前的东西,回帖又获得了10分可用分,哈哈。