0

I am having a problem with a script on this website I try to build. This is the script itself:

var id=0;
var cases=$('.cases').length;
$('#show').html($('#'+id).html());
setInterval(function() 
{
    $('#show').empty();
    if (id==cases-1)
        id=0;
    else
        id++;
    $('#show').html($('#'+id).html());
},5000);

this is the html code:

<div class="page">
    <br /><br /><headline>cases</headline><br /><br /><div id='case'></div><div class='content'><div id='show'></div><div id='column1'><div class='cases' id='0'><div class='short'><div id='cases-image'><img src='images/Sunset.jpg'/></div><div id='cases-info'><div id='cases-headline'>zxfbzsxdbfsdfh</div><cases-text>dfghsdfgsdfgsdfg</cases-text><div class='more' id=zxfbzsxdbfsdfh >להמשך קריאה...</div></div></div></div></div><div id='column2'><div class='cases' id='1'><div class='short'><div id='cases-image'><img src='images/גלריה1.bmp'/></div><div id='cases-info'><div id='cases-headline'>xbzsdfbsdf</div><cases-text>dafasdvasdvasdv</cases-text><div class='more' id=xbzsdfbsdf >להמשך קריאה...</div></div></div></div></div>            </div>
        <div id="footer">
</div>

It works in jsFiddle, but it doesn't work on my computer, it only shows the first case, the id in the script changes, but it doesn't get the html from the other cases... Can you help me?

4

2 に答える 2

1

次のように使用してみてください。

<script src="http://code.jquery.com/jquery-latest.js"></script>

<script type="text/javascript">

$(document).ready(function(){

    var id=0;
    var cases=$('.cases').length;
    $('#show').html($('#'+id).html());
    setInterval(function() 
    {
        $('#show').empty();
        if (id==cases-1)
            id=0;
        else
            id++;
        $('#show').html($('#'+id).html());
    },5000);

});
</script>

コードがフィドルで機能する場合は、規則に従えば確実にコンピューターで機能するはずです。

于 2012-11-10T10:05:21.833 に答える
0

確実に

jQuery.jsを含めました

次のような準備完了ハンドラー内にコードをラップしました

<script type="text/javascript">
$(function(){
 //your code
});
</script>
于 2012-11-10T10:05:31.743 に答える