28,390
社区成员
发帖
与我相关
我的任务
分享
<!doctype html>
<html>
<head>
<meta charset="gb2312">
<title>无标题文档</title>
</head>
<body>
<input name="name" type="text" id="name" size="50">
</body>
</html>
下面是获取列表的代码
<script>
function GetRandomNum(Min,Max)
{
var Range = Max - Min;
var Rand = Math.random();
return(Min + Math.round(Rand * Range));
}
var arr = [];
<%
Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(Server.MapPath("."))
Set files = f.Files
For Each file in files
%>
var file_name = "<%= file.Name %>";
var nReg = /\.jpg$|\.jpeg$|\.gif$|\.png$/i;
if (nReg.test(file_name)) {
arr.push('/images/'+file_name);
};
<%
Next
%>
console.log(arr);
var index = GetRandomNum(0,(arr.length-1) );
document.getElementById("name").value=arr[index];
</script>
上面已解决了图片格式的问题,但如何获得列表后按顺序填入文本框?
<!doctype html>
<html>
<head>
<meta charset="gb2312">
<title>无标题文档</title>
</head>
<body>
<input type="text" name="name" id="name">
</body>
</html>
下面是获取列表的代码
<script>
function GetRandomNum(Min,Max)
{
var Range = Max - Min;
var Rand = Math.random();
return(Min + Math.round(Rand * Range));
}
var arr = [];
<%
Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(Server.MapPath("."))
Set files = f.Files
For Each file in files
%>
arr.push("<%= file.Name %>");
<%
Next
%>
var index = GetRandomNum(1,arr.length );
document.getElementById("name").value=arr[index];
</script>