Event Listener, bubble sort, switching picture, carousel

Event listener method:

var a11 = document.getElementById ( 'id1'); // Get first tag

var a22 = document.getElementById ( 'id1'); // Get first tag

a11.addEventListener ( 'click', show); // elements to addEventListener click event.

a22.onClick=function{

a11.removeEventListener ( 'click', show); After adding click event -remove out on the label of the event to another element

function show () {} // Set the click event show

Bubble Sort:

Array array = [9,4,3,1,2,6,7,8,5,0] Sort

function(){

for(var i=0;i<array.length;i++){   //循环length遍

  for(var j=0;j<array.lenth-j;i++){

  if (array [j]> array [j + 1] ({// two adjacent numbers comparison, if a number is greater than a few before, the number of two interchangeable.

  temp = array [j]; // swap

  array[j]=array[j+1];

  array[j+1]=temp;

} } } }

Click to switch on a map, the next map:

The picture address into an array by calling the index.

var array=['img/1.png','img/2.png','img/3.png];

Set an img tag, used to put pictures

var img1 = getElementById ( 'id'); obtaining this label is set to onClick = "next ()"

var num = 1; the initial value of the set index.

Set click event function next () {

Img1 setting the src attribute of an array index next picture, namely:

img1.setAttribute('src',array[num]);

num ++; add cycle

After due num <= array.length-1, it is provided more than the maximum num index allows to restore the minimum value 0;

if(num>array.length-1){

a = 0;}

Carousel Figure:

 To the next () method of the above-described switching a map used to set the timer can be realized setInternal: every 1 second at a handover.

var time1 = setInterval ( 'next ()', 1000); // called once every 1 second next ()

function stop () {// call stop method to clear the timer.

clearInterval('next()',1000);}    

function start () {// call the start method you can set the timer.

time1=setInterval('next()',1000);}  

Guess you like

Origin www.cnblogs.com/god3064371/p/11375222.html