首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

小弟我想做一个每秒钟弹窗一次

2012-05-28 
我想做一个每秒钟弹窗一次。window.onload function(){var 弹窗 new 方法(Hello World!)弹窗.alert(

我想做一个每秒钟弹窗一次。
window.onload = function(){
  var 弹窗 = new 方法("Hello World!");
  弹窗.alert();

  }

  function 方法(msg) {

  this.msg = msg;

  this.alert = function () {
  alert(this.msg);
  setTimeout("this.alert()",1000); }

   
   
  }
大家看一下我哪里错了。

[解决办法]

HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title><script type="text/javascript">function Messager(msg) {    this.msg = msg;}Messager.prototype.alert = function() {        alert(this.msg);        var fn = null;    if (this.alert.bind) {        fn = this.alert.bind(this);    } else {        var targetThis = this;        fn = function() {            targetThis.alert.apply(targetThis, arguments);        };    }    setTimeout(fn, 1000);};window.onload = function() {        new Messager("Hello").alert();    }</script></head><body></body></html>
[解决办法]
改一行代码:
setTimeout("window.onload()",1000); 

热点排行