html id自动点击,Javascript中的addEventListener自动触发点击事件

我想制作一个简单的javascript倒计时程序。出于某种原因,倒计时触发不需要我点击启动链接。Javascript中的addEventListener自动触发点击事件

My Top Ten Movies

Countdown Suren's favorite ten movies

Start

NumberMovie

和我的JavaScript文件...

//get the start element

var start = document.getElementById("start");

//register listener

start.addEventListener('click', startCountDown(), false);

function startCountDown()

{

//alert("Here!");

//creat the list of 10 movies

var myTenMovies = ["Breaveheart", "Mars Attacks", "Startship Troopers", "Jurassic Park", "Terminator 2",

"Austion Powers: Gold Member", "Fifth Element", "Bram Stocker's Dracula",

"Shashank Redemption", "LOTR: Return Of The King"];

//get the location in the DOM to add each movie

var tableLocation = document.getElementById("movieList");

//create a timer function

var countdown = setInterval(insertNextMovie, 750);

//keep track of the index

var index = 0;

var movieRankIndex = 10;

//alert("1");

//function to add to DOM

function insertNextMovie()

{

//alert("Here3!");

//create a text nodes

var movie = document.createTextNode(myTenMovies[index]);

var rank = document.createTextNode(movieRankIndex);

//create

element

var rankData = document.createElement("td");

var movieTitle = document.createElement("td");

var row = document.createElement("tr");

//add text to td

rankData.appendChild(rank);

movieTitle.appendChild(movie);

//fill the row with data

row.appendChild(rankData);

row.appendChild(movieTitle);

if(movieRankIndex == 1)

{

row.setAttribute("bgcolor", "yellow");

//row.setAttribute("align", "right");

}

//add td to DOM table

tableLocation.appendChild(row);

//append index

index++;

movieRankIndex--;

if(index == 10)

{

clearInterval(countdown);

}

}

//alert("2");

}

2012-07-15

Suren

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
©️2021 CSDN 皮肤主题: 1024 设计师:白松林 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值