我有这个非常简单的jQuery脚本,它给我带来了错误,即延迟不是函数。

我究竟做错了什么?事情是一切正常,除了延迟会导致错误:S

我确保只加载一次jquery库,这也是最新版本1.7.1。

function    statusInquiry(orderItemID)
{
    var loadUrl = "bl_updaInfo.php";

    $.post(
        loadUrl,
        {"orderItemID": orderItemID, "type": "statusInquiry"},
        function(responseText){
            $("#reportArea" + orderItemID).fadeIn("slow").html(responseText);
        },
        "html"
    );
    updateLogList(orderItemID);

    $("#reportArea" + orderItemID).delay(10000).fadeOut("slow");
}


错误:
-[19:44:10.792] $("#reportArea" + orderItemID).delay is not a function

responseText就是这样:

<table class="tablerainbow-noborder" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="color: #888786;" width="70%">Client requests status for this search.</td>
<td style="color: #888786;">Posted 2012-03-12 12:34:22 by Client</td>
</tr>
</tbody>
</table>

最佳答案

您正在传递string值。您是否尝试过传递数字(不带引号)?

另外,您确定要按照预期的方式使用它吗?根据jQuery API docsdelay影响队列中的下一个动画,而不影响已经执行的动画。

最终,答案取决于您想做什么。如果在呼叫链中fadeOut之后出现delay,则delay命令将不受呼叫fadeOut的影响。如果要在fadeOut出现之前暂停一会,则需要切换两个呼叫。

编辑:基于与@Adrov的一些交互的更多想法。

postjQuery API docs中,您可能想看一下responseText对象进入success回调时的内容。如果将完整的HTML页面放入现有的div标记中,则会导致冲突和奇怪的行为。下面的示例直接来自jQuery文档。注意在将数据放入现有页面之前,如何对结果执行find

$.post( url, { s: term },
      function( data ) {
          var content = $( data ).find( '#content' );
          $( "#result" ).empty().append( content );
      }
    );


编辑注释:Ken Redler's answer建议在delay方法的fadeOut回调内链接successpost方法。我只是想确保这个建议不会丢失,因为这是一个很好的建议。

09-30 16:37
查看更多