kidapu
9/17/2015 - 7:50 AM

抽選用スクリプト

抽選用スクリプト

<!DOCTYPE html>
<html>
<title>アンケート抽選用</title>
<body>

<script type="text/javascript">

var names = [
"Aさん",
"Bさん",
"Cさん",
"Dさん",
"Eさん"];
var max_num = 3;

Array.prototype.shuffle = function()
{
	var i = this.length;
	while (i)
	{
		var j = Math.floor(Math.random() * i);
		var t = this[--i];
		this[i] = this[j];
		this[j] = t;
	}
	return this;
}

names.shuffle();

for (var i=0; i<max_num; i++) 
{
	var p = document.createElement('p');
	p.innerHTML = (i+1) + "位:" + names[i]; 
	document.body.appendChild(p);
}

</script>
</body>
</html>