Jquery $(document.body).append()不';他似乎不在IE工作

Jquery $(document.body).append()不';他似乎不在IE工作,jquery,internet-explorer,append,document-body,Jquery,Internet Explorer,Append,Document Body,当我的用户的会话到期并且默认页面在母版页下被引用时,我将用户重定向到我的default.aspx。我显示了一个类似于twitter的通知,声明会话已过期,发生了什么事?它在firefox和google chrome中工作正常,但在IE中工作不正常。我得到Internet Explorer无法打开站点-http://localhost:1335/order/Default.aspx?Sid=1 操作中止 我在谷歌上搜索了一下,发现body标记之前有一个$(document.body).append

当我的用户的会话到期并且默认页面在母版页下被引用时,我将用户重定向到我的default.aspx。我显示了一个类似于twitter的通知,声明会话已过期,发生了什么事?它在firefox和google chrome中工作正常,但在IE中工作不正常。我得到
Internet Explorer无法打开站点-http://localhost:1335/order/Default.aspx?Sid=1 操作中止

我在谷歌上搜索了一下,发现body标记之前有一个
$(document.body).append()
,如果我将脚本移动到页面底部,则我的通知在任何浏览器中都不起作用

这是我的主页

<head runat="server">
    <title></title>

    <script src="Javascript/Jquery1.4.js" type="text/javascript"></script>

    <script type="text/javascript">
        function topBar(message) {
            $("#alertmsg").remove();
            var $alertdiv = $('<div id = "alertmsg"/>');
            $alertdiv.text(message);
            $alertdiv.bind('click', function() {
                $(this).slideUp(200);
            });
            $(document.body).append($alertdiv);
            $("#alertmsg").slideDown("slow");
            setTimeout(function() { $alertdiv.slideUp(200); }, 5000);
        }
    </script>

    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>

我找不到调用
topBar
的位置,但是如果我从
$(document.ready()
调用它,它就像我的IE8中的一个符咒:

<script type="text/javascript"> 
    function topBar(message) { 
        $("#alertmsg").remove(); 
        var $alertdiv = $('<div id = "alertmsg"/>'); 
        $alertdiv.text(message); 
        $alertdiv.bind('click', function() { 
            $(this).slideUp(200); 
        }); 
        $(document.body).append($alertdiv); 
        $("#alertmsg").slideDown("slow"); 
        setTimeout(function() { $alertdiv.slideUp(200); }, 5000);
    }

    $(document).ready(function() {
        topBar("Hello world!");
    });
</script> 
希望能有帮助

编辑:


也许能帮点忙?基本上你可以这样做:

ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "json",  
    @"$(document).ready(function(){   
             topBar("Hello world!");
             }); 
        });", true); 

查看链接中的,因为他给出了两个备选方案

何时调用
topBar
函数?@casablanca我更新了我的问题。我不熟悉ASP.NET。您能否查看生成的页面源代码并查看函数的实际调用位置?可能是调用太早了,也就是说,在解析主体之前。@casablanca charlie的答案起作用了。我在编辑函数调用位置之前回答了这个问题,因为我刚刚被研究过,以便能够更新我的答案。我在没有任何解释的情况下投了反对票。我想它没有回答现在提出的问题,但是根据我当时得到的信息,我认为这是一个有效的答案。在你发布这个答案之前4分钟,我已经编辑了这个问题。也许我的打字速度不是最快的,我需要测试结果?不管怎样,没有什么不愉快的感觉。我已经更新了我的答案,希望它能让你继续。你的答案成功了。很抱歉最初投了否决票,因为我知道更新之前您给出的答案。无论如何,谢谢你,伙计,别难过,没问题!我很高兴能帮上忙
$(window).load(function() {
    topBar("Hello world!");
});
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "json",  
    @"$(document).ready(function(){   
             topBar("Hello world!");
             }); 
        });", true);