1

我有一个 div 幻灯片。我有几个 div,每个 div 都有一个名为 rotate 的类,并且该 div 中有更多 div。我的任务是检查后缀为 _note3 的 div 是否包含 0 以从幻灯片中排除该幻灯片。零将来自 SQL 服务器。我可以将它从幻灯片中排除,但在删除零时我无法将其放回原处。我想知道是否有人知道我做错了什么并帮助我找到解决方案。

我的代码如下所示:

 $(document).ready(function() {

    var note3 = [];
    var divsCount = 0;
    var ids = [];
    var count = 0;
    var divs = [];
    var removed = [];

    for(var x = 0; x < $(".rotate").length; x++) {
        notes3(divsCount);
        getRotate(divsCount);
        divsCount++;
    }
    // I find all the _note3 divs
    function notes3(index) {
        note3.push($('div[id*="_note3"]:eq(' + index + ')').attr("id"));
    }

    for (var t = 0; t < $(".rotate").length; t++) {
        $(".rotate").eq(t).hide();

    }
    // I find put all the rotate divs in an array
    function getRotate(index) {
        divs.push($('div[class*="rotate"]:eq(' + index + ')').attr("class"));
    }

    // This is where my rotation happens
    function setsRotation() {




        $(".rotate").eq(count).hide();
        if (count < $(".rotate").length - 1) {
            count++;
        }
        else {
            count = 0;
        }

// If it contains a zero I remove it
    if($("#" + note3[count] + "").text() === $.trim("0")) {
// I put the div index in an array
        removed.push(count);
        $('div[class*="rotate"]:eq(' + count + ')').remove();
        // If it does not contain a zero
    } else {

    // If the index is in the removed array I take it out and append the div
        if($.inArray(count, removed) > - 1) {

            removed.splice($.inArray(count, removed), 1);

            $("#slideshow").append(divs[count]);
        }

        $('div[class*="rotate"]:eq(' + count + ')').show();

    }
    }
    setInterval(setsRotation, 1000);
    }); 

先谢谢了!

HTML:

<div id="slideshow">
<div class="rotate" id="jrkC">
<div>
        <div id="JerkChknLg_desc" class="descript"></div><div id="JerChknLg_note3"></div>
    <table class="pepper">

    <tr>
        <td class="size">Regular ds</td>
        <td class="size">Large</td>
    </tr>
    <tr>
        <td class="value"><div id="JerkChknSm_price"></div></td>
        <td class="value"><div id="JerkChknLg_price"></div></td>
    </tr>
</table>
<div class="frontPic"><img src="media/img/JerkChkn.jpg"/></div>
</div>
</div>

<div class="rotate" id="soups" >
<div  id="">
        <div id="SoupLrg_desc" class="descript"></div><div id="SoupLrg_note3"></div>
    <table class="pepper">

    <tr>
        <td class="size">Regular</td>
        <td class="size">Large</td>
    </tr>
    <tr>
        <td class="value"><div id="SoupSm_price"></div></td>
        <td class="value"><div id="SoupLrg_price"></div></td>
    </tr>
</table>
<div class="frontPic"><img src="media/img/Soup.jpg"/></div>
</div>
</div>
4

0 回答 0