A random naming function implemented by javascript.
This is actually an exercise method for JS random numbers. First, we should prewrite everyone's names in an array, and then let the values in the array quickly display in the area, when you press the stop button, the rolling will stop to achieve a random effect.
<! DOCTYPE html>
Who will use javascript to write a random name system?
Who has this worry!
Using arrays and timers in JavaScript to achieve random names
The aa is the array of names.
<Script language = "JavaScript">
<! --
Var aa = ["Zhao", "Qian", "Sun", "Li"]
Var I = 0;
Var t;
Function startCall ()
{
I ++;
Var name = document. getElementById ("n ");
If (I> = 4)
{
I = I % 4
}
T = setTimeout ("startCall ()", 100); // The 2nd parameters can change the name conversion time, in milliseconds.
Name. value = aa [I]
}
Function stopCall ()
{
ClearTimeout (t );
Var name = document. getElementById ("n ");
Name. value = aa [I]
}
// -->
</SCRIPT>
<BODY>
NAME <input type = "text" id = "n" NAME = "">
<Input type = "button" VALUE = "start" ONCLICK = "startCall ()">
<Input type = "button" VALUE = "stop" ONCLICK = "stopCall ()">
</BODY>