setTimeout不起作用?

时间:2015-05-20 02:25:53

标签: javascript c# asp.net-mvc

我的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

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

但我的setTimeout无法正常工作。我该怎么办?

2 个答案:

答案 0 :(得分:1)

Setimeout应写成如下

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

无括号。

答案 1 :(得分:0)

有身体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