2016-05-23 2 views
0

У меня возникли проблемы с закрытием модальности, которую я создаю в javascript. Идея состоит в том, чтобы показать загрузочный круг во время получения данных, а затем скрыть его, как только это будет сделано в фоновом режиме. Все работает отлично, пока я не попытаюсь скрыть это. Кажется, ничего не происходит? Он просто висит ...Закрытие всплывающего окна, созданного с помощью Javascript от codebehind

enter image description here

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); 

ответ

2

Поскольку вы определили идентификатор динамически созданного элемента. Используйте ID Selector (“#id”)

Выбор одного элемента с заданным идентификатором атрибута

Применение

$("#loadingCircle2") 

вместо

$find("loadingCircle2") 

Вы не правильно установили свойство ID, так как его id и modal - это объект jQuery, также вы не добавляете элемент loading к модальному.

Complete Script

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(); 
} 
+0

Это, кажется, не работает? –

Смежные вопросы