日期:2014-05-16 浏览次数:20446 次
<input id="txt_tname" name="" type="text" value="" /> <input id="btn_submit" name="" type="button" />
<!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" />
<title>无标题文档</title>
<script type="text/javascript">
var ar = [];
window.onload = function() {
document.getElementById('btn_submit').onclick = function() {
var v = document.getElementById('btn_tname').value;
if (v.length > 0) {
var FLAG = false;
for (var i in ar) {
if (ar[i].key == v) {
FLAG = true;
alert(ar[i].val);
break;
}
}
if (!FLAG) ar.push({key: v, val: Math.random()});
}
}
}
</script>
</head>
<body>
<input id="btn_tname" name="" type="text" value="" />
<input id="btn_submit" name="" type="button" value="添加到数组" />
</body>
</html>
------解决方案--------------------
Math.round(Math.random() * 7)