开发者

Modal Window load dynamic content and change it in times

Hy guys.

I have a modal window that loads a page and I need to, after 90 seconds load another page.

I have...

    <table id="table4">
    <tr>
        <td>Id:</td>
        <td>Nome:</td>
    </tr>
    <tr>
        <td>1515</td>
        <td>Thiago</td>
    </tr>
    <tr>
        <td>2015</td>
        <td>Guttierre</td>
    </tr>
</table>

According to the ID, i will load a page that the id represents.. like http://www.test.com/1515. and after 90 seconds I have to load the other id... http://www.test.com/2015.

Now I have this script...

$(document).ready(function() {

//seleciona os elementos a com atributo name="modal"
var aux = 2;
while (($("#table4 tr:nth-child(" + aux + ") td:nth-child(1)") != "")) {

    var idSOS = $("#table4 tr:nth-child(" + aux + ") td:nth-child(1)").text();
    if ((idSOS != "") && (idSOS != undefined) && (idSOS != null) && (idSOS != "Id:")) {


        $("#dialog, #mask,#closediv").css开发者_如何学运维({ 'display': 'block' });
        var maskHeight = "99%";
        var maskWidth = "99%";
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        //Effect
        $('#mask').fadeIn(800);
        $("#dialog").fadeIn(1600);
        $('#mask').fadeTo("slow", 1);
        $('#dialog').fadeTo("slow", 1);

        //
        var winH = $(window).height();
        var winW = $(window).width();
        //centraliza na tela a janela popup
        $("#dialog, #mask").css('top', '2px');
        $("#dialog, #mask").css('left', '2px');

        //

        setTimeout(function() {
            var i = idSOS;
            loadContent(i);
        }, 10000);





        aux++;
        //            continue;
    } //end IF
    else {
        $("#dialog").empty();
        $("#dialog, #mask").hide();
        break;
    };


}; //END WHILE


$("#dialog, #mask").hide();

//se o botão fechar/tela for clicado
$('#closediv').click(function GetOut(e) {
    e.preventDefault();
    $('#mask,#closediv, .window').hide();
});

function loadContent(idSOS) {
    $("#dialog").load('/teste' + idSOS + '.aspx');
};

It only shows the second id loaded in the div. What I have to do to load the first ID loaded in the DIV "dialog" and then, after 90 seconds, show the second ID?

Where did I go wrong?

Thks folks.


I believe this happens because setTimeout expects first parameter to be a string, and you gave it a function, which is probably being executed right away

so the code should be more like:

setTimeout("function() { ... }", 90000);

however, your logic still appears to have flaws, as the "each" statement will create 2 setTimeout() functions that will both be executed at the same time after 90 seconds.

This is because it will iterate over both columns (TD) present and execute everything that is in the "each" part every time.

The code most probably needs a more detailed revision.


This line is clearing the dialog right after loading it:

$("#dialog").empty();

Then, in the 90 second timeout, it loads the second item successfully.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜