SetTimeout从文档中删除对象的实例

时间:2014-02-20 12:09:10

标签: jquery settimeout cleartimeout

需要setTimeout()方法的帮助。

我在这里有以下代码:

我需要能够删除newState变量的实例。认为我做错了。请协助。提前致谢。

var deleteState = setTimeout("alert('Object has been removed')" , 2000);
newState.mousedown(function(e) {
    if (deleteState == 0) {
        clearTimeout(deleteState);
    }

    jsPlumb.detachAllConnections($(this));
    $(this).remove();
    e.stopPropagation();
}); 

1 个答案:

答案 0 :(得分:-1)

试试这个:

var deleteState = setTimeout(function(){alert('Object has been removed') } , 2000);

来源:http://www.w3schools.com/js/js_timing.asp