SoFunction
Updated on 2025-03-08

A random call function implemented by javascript

A random call function implemented by javascript

Updated: August 26, 2014 11:52:19 Submission: junjie
This article mainly introduces a random call function implemented by JS. It has simple logic and is a good choice for use in class or activities. Friends who need it can refer to it.

This is actually an exercise for JS random numbers. First write down everyone's names in an array in advance, and then let the values ​​in the array be displayed quickly in the area. When you press stop, scrolling will stop to achieve a random effect.

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<title>JSRandomly named - Qiongtai Blog</title>
	<script type="text/javascript">
	var isRun=true;
	var a = ["Zhang San","Li Si","Wang Wu","Zhao Liu"];	
	var a2 = new Array();
	function action(str){
		var s = ("bt").value;
		if(s=="start"){
			isRun=true;
			run();
			("bt").value="Finish";
		}else{
			isRun=false;
			("bt").value="start";
		}
	}
	function run(){
		var i = (() * + 1)-1;
		("show").innerHTML=a[i];
		if(isRun==false){
			var b =true;
			for(var j in a2){
				if(a2[j]==i){
					b=false;
				}
			}
			if(b){
			 	a2[]=i;
				return;
			}
		}
		setTimeout("run()",10);
	}
</script>

</head>

<body>
	<div style="text-align:center; margin-top:100px;width:100%;">
		<div  style="margin:auto;font-size:50px;width:100px;height:50px; background:#FFEEFF"></div>
		<div style="margin-top:20px;">
			<input  type="button" onclick="action()" value="start"/>
		</div>
	</div>
</body>
</html>

  • javascript
  • Random name

Related Articles

  • Delete the key in the middle of Javascript Object

    This article introduces the method of deleting the key in the Javascript Object, and then mainly talks about the usage of delete in detail. It is very detailed, so please refer to it for your friends.
    2014-11-11
  • The basics of prototype concepts of Object objects in JS

    This article is a basic content about JS learning. Learn the prototype concept of Object objects. If you are interested, please refer to it.
    2018-01-01
  • JavaScript Learning Notes Recording My Journey

    JavaScript and Java have no direct relationship. The only relationship is that JavaScript is originally named LiveScript. Later, it absorbed some features of Java and upgraded to JavaScript. JavaScript is sometimes referred to as JS.
    2012-05-05
  • In-depth interpretation of Iterator and for-of loops in JavaScript

    This article mainly introduces Iterator and for-of loops in JavaScript, which are the basic knowledge in JS introduction. Friends who need it can refer to it.
    2015-07-07
  • Detailed explanation of the difference between JavaScript parseInt() and Number()

    This article mainly introduces a detailed explanation of the difference between JavaScript parseInt() and Number() cases. This article explains the understanding and use of this technology through brief cases. The following is the detailed content. Friends who need it can refer to it.
    2021-09-09
  • JS rounding problem with special data

    JS rounding problem with special data...
    2007-02-02
  • Detailed explanation of JavaScript cookies and simple example applications

    This article mainly introduces the detailed explanation of JavaScript cookies and the relevant information on simple example applications. Here we explain the introduction of js cookies, basic properties and simple applications. Friends who need it can refer to it.
    2016-12-12
  • Detailed explanation of the event loop mechanism of JS browser

    This article mainly introduces the event loop mechanism of the JS browser. The example code is introduced in this article in detail, which has certain reference learning value for everyone's learning or work. Friends who need it, please learn with the editor below.
    2019-03-03
  • Javascript learning notes Functions (III): Closures and citations

    This series has not been updated for a long time. Today I will take it back and continue with the unfinished items. In this article, we will talk about one of the most important features in Javascript - references to the use of closures.
    2014-11-11
  • A deep understanding of JavaScript series (49): Function mode (Part 1)

    This article mainly introduces an in-depth understanding of JavaScript series (49): Function mode (Part 1). This article explains callback functions, configuration objects, return functions, partial applications, currying and other content. Friends who need it can refer to it.
    2015-03-03

Latest Comments