读书人

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

发布时间: 2012-05-28 17:59:33 作者: rapoo

我想做一个每秒钟弹窗一次。
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);

读书人网 >JavaScript

热点推荐