求个JS静态页面,效果是点击一个按钮,生成5个随机数,要不重复 最好是有一个增加按钮一个减少和一个生成按钮,增加减少按钮是控制文本框多少,生成按钮是点击后在文本框里生成一个0-9的随机数,并且所有的文本框里的数不重复,文本框最多增加到10个,最少一个。最主要的是生成几个0-9的随机数要不重复, 谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 数组随机排序:http://hi.baidu.com/iamzhangxinxu/blog/item/4dd14709eed006db62d986be.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> <style type="text/css"> .textbox { margin-right: 5px; margin-top: 10px; width: 25px; font-family: 微软雅黑; text-align: center; font-weight: bold; font-size: 16px; color: Blue; } </style> <script type="text/javascript"> function CreateTextBox() { var count = GetTextBoxCount(); if (count < 10) { var textBox = document.createElement("input"); textBox.setAttribute("type", "text"); textBox.setAttribute("name", "myname"); textBox.className = "textbox"; document.body.appendChild(textBox); } else { alert("最多生成10个随机数"); } } function RemoveTextBox() { var count = GetTextBoxCount(); if (count > 1) { document.body.removeChild(document.body.lastChild); } else { alert("请最少保留1个"); } } function GetTextBoxCount() { var elements = document.getElementsByName("myname"); return elements.length; } Array.prototype.Contains = function (num) { var flag = false; if (this.length <= 0) { return flag; } for (var i = 0; i < this.length; i++) { if (this[i] == num) { flag = true; break; } } return flag; } function CreateRandomNumber(array, count) { while (array.length < count) { var num = Math.floor(Math.random() * 10); if (!array.Contains(num)) { array.push(num); } } } function SetTextBoxValue() { var array = new Array(); var count = GetTextBoxCount(); CreateRandomNumber(array, count); var elements = document.getElementsByName("myname"); for (var i = 0; i < elements.length; i++) { elements[i].value = array[i]; } } </script></head><body onload="CreateTextBox()"> <input type="button" value="增加" onclick="CreateTextBox()" /> <input type="button" value="减少" onclick="RemoveTextBox()" /> <input type="button" value="生成随机数" onclick="SetTextBoxValue()" /><br /></body></html> 求个js 效果。禁止右键。 求助!JavaScript制作右下角信息提示窗口 请教有关载入指定网站的问题 如何JS加载外部的CSS |zyciis| 如何那一个对像定义一个属性,而这个属性是通过方法取值和赋值,谢谢 当text文本框的value改变触发什么事件? 为什么我的div位置会随着窗口的大小而变化,怎么解决? 哪位高人能进一步把小窗口单独弄出来? 谁能帮帮我?本人急需JAVAScript经典教程!!必有重谢!!! 怎样在HTML代码中使用JAVASCRIPT中变量的值 html + javascript js从后台拿数据以表格显示
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
.textbox
{
margin-right: 5px;
margin-top: 10px;
width: 25px;
font-family: 微软雅黑;
text-align: center;
font-weight: bold;
font-size: 16px;
color: Blue;
}
</style>
<script type="text/javascript">
function CreateTextBox() {
var count = GetTextBoxCount();
if (count < 10) {
var textBox = document.createElement("input");
textBox.setAttribute("type", "text");
textBox.setAttribute("name", "myname");
textBox.className = "textbox";
document.body.appendChild(textBox);
} else {
alert("最多生成10个随机数");
}
}
function RemoveTextBox() {
var count = GetTextBoxCount();
if (count > 1) {
document.body.removeChild(document.body.lastChild);
}
else {
alert("请最少保留1个");
}
}
function GetTextBoxCount() {
var elements = document.getElementsByName("myname");
return elements.length;
}
Array.prototype.Contains = function (num) {
var flag = false;
if (this.length <= 0) {
return flag;
}
for (var i = 0; i < this.length; i++) {
if (this[i] == num) {
flag = true;
break;
}
}
return flag;
}
function CreateRandomNumber(array, count) {
while (array.length < count) {
var num = Math.floor(Math.random() * 10);
if (!array.Contains(num)) {
array.push(num);
}
}
}
function SetTextBoxValue() {
var array = new Array();
var count = GetTextBoxCount();
CreateRandomNumber(array, count);
var elements = document.getElementsByName("myname");
for (var i = 0; i < elements.length; i++) {
elements[i].value = array[i];
}
}
</script>
</head>
<body onload="CreateTextBox()">
<input type="button" value="增加" onclick="CreateTextBox()" />
<input type="button" value="减少" onclick="RemoveTextBox()" />
<input type="button" value="生成随机数" onclick="SetTextBoxValue()" /><br />
</body>
</html>