关闭从codebehind通过Javascript创建的弹出窗口

关闭从codebehind通过Javascript创建的弹出窗口,javascript,asp.net,c#-3.0,Javascript,Asp.net,C# 3.0,关闭我在javascript中创建的模式时遇到一些问题。其思想是在检索数据时显示加载循环,然后在后台完成后将其隐藏。一切都很好,直到我试图隐藏它。什么都没发生?它就挂在那里 显示/隐藏加载循环的Javascript: <style type="text/css"> .modal { position: fixed; top: 0; left: 0; background-color: black; z-index: 99; opac

关闭我在javascript中创建的模式时遇到一些问题。其思想是在检索数据时显示加载循环,然后在后台完成后将其隐藏。一切都很好,直到我试图隐藏它。什么都没发生?它就挂在那里

显示/隐藏加载循环的Javascript:

<style type="text/css">

.modal
{
    position: fixed;
    top: 0;
    left: 0;
    background-color: black;
    z-index: 99;
    opacity: 0.8;
    filter: alpha(opacity=80);
    -moz-opacity: 0.8;
    min-height: 100%;
    width: 100%;
}
.loading
{
    font-family: Arial;
    font-size: 10pt;
    border: 5px solid blue;
    width: 200px;
    height: 100px;
    display: none;
    position: fixed;
    background-color: white;
    z-index: 999;
}
</style>


<script type="text/javascript">
    function ShowLoadingCircle()
    {
        var modal = $('<div />');
        modal.ID = "loadingCircle2";
        modal.addClass("modal");           
        $('body').append(modal);
        var loading = $(".loading");
        var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
        var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
        loading.css({ top: top, left: left });
        loading.show();
    }

    function HideLoadingCircle()
    {
        var loadingCirlce = $find("loadingCircle2");
        loadingCirlce.hide();
    }
</script>
ScriptManager.RegisterStartupScript(this, this.GetType(), "Show Me", "setTimeout('ShowLoadingCircle()', 10);", true);

ScriptManager.RegisterStartupScript(this, this.GetType(), "Hide Me", "setTimeout('HideLoadingCircle()', 0);", true);

因为您已经定义了动态创建的元素的ID。使用

选择具有给定id属性的单个元素

使用

而不是

$find("loadingCircle2")

您没有正确设置ID属性,因为它的
ID
modal
是一个jQuery对象,而且您没有将
加载
元素附加到modal

全本

函数ShowLoadingCircle()
{
//创建DIV
var模态=$(''{
“id”:“加载循环2”,
“类”:“模态”,
});        
//设置加载
变量加载=$(“.loading”);
var top=Math.max($(window.height()/2-load[0].offsetHeight/2,0);
var left=Math.max($(窗口).width()/2-正在加载[0].offsetWidth/2,0);
正在加载.css({top:top,left:left});
//附加加载
模态附加(加载);
//附加情态动词
$('body')。附加(模态);
}
函数HideLoadingCircle()
{
$(“#加载循环2”).hide();
}

因为您已经定义了动态创建元素的ID。使用

选择具有给定id属性的单个元素

使用

而不是

$find("loadingCircle2")

您没有正确设置ID属性,因为它的
ID
modal
是一个jQuery对象,而且您没有将
加载
元素附加到modal

全本

函数ShowLoadingCircle()
{
//创建DIV
var模态=$(''{
“id”:“加载循环2”,
“类”:“模态”,
});        
//设置加载
变量加载=$(“.loading”);
var top=Math.max($(window.height()/2-load[0].offsetHeight/2,0);
var left=Math.max($(窗口).width()/2-正在加载[0].offsetWidth/2,0);
正在加载.css({top:top,left:left});
//附加加载
模态附加(加载);
//附加情态动词
$('body')。附加(模态);
}
函数HideLoadingCircle()
{
$(“#加载循环2”).hide();
}
function ShowLoadingCircle()
{
    //Create DIV
    var modal = $('<div />', {
        "id" : "loadingCircle2",
        "class" : "modal",
    });        

    //Set loading 
    var loading = $(".loading");
    var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
    var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
    loading.css({ top: top, left: left });

    //Append the loading
    modal.append(loading);

    //Append the modal
    $('body').append(modal);
}

function HideLoadingCircle()
{
    $("#loadingCircle2").hide();
}