setTimeout不起作用

本文关键字:不起作用 setTimeout | 更新日期: 2023-09-27 17:49:45

我的JavaScript代码是这样的:

<script type="text/javascript">
                        ZeroClipboard.config({ swfPath:     "/Content/ZeroClipboard.swf" });
                        var client = new ZeroClipboard($(".copy-button"));
                        client.on('copy', function (event) {
                            event.clipboardData.setData('text/plain', event.target.innerText);
                        });
                        client.on("aftercopy", function (event) {
                            $("#alerta button").after('<span>Matricula copiada</span>');
                            $('#alerta').fadeIn('slow');
                            $('#alerta').setTimeout(close(), 3000);
                             });
                    </script>

和我有div在body:

  <div class="alert alert-info" id="alerta" style="display: none; ">
     <button type="button" class="close"></button>
         </div>

但是我的setTimeout不工作。我能做什么?

setTimeout不起作用

Setimeout应该这样写

$('#alerta').setTimeout(close, 3000);

没有括号。

有正文div

<div class="alert alert-info" id="alert" style="display: none; ">
    <button type="button" class="alertaderecha">La matrícula ha sido    copiada.</button>

还有javascript:

<script type="text/javascript">
    ZeroClipboard.config({ swfPath: "/Content/ZeroClipboard.swf"});
    var client = new ZeroClipboard($(".copy-button"));
    client.on('copy', function (event) {
        event.clipboardData.setData('text/plain', event.target.innerText);
    });
    client.on("aftercopy", function (event) {
        var message = $("#alert").after('');
        $('#alert').fadeIn('slow');
        var time = setTimeout(function (e) {
            message.hide();
        }, 3000);
    });
</script>

有任何答案请在这里提问

特别感谢@ Stephen Muecke