English 中文(简体)
简单 Javascrap 幻灯片功能不工作
原标题:Simple Javascript slide function not working

我新到 Javascript, 我试图用图像做一个简单的幻灯片放映。 这是我的代码, 如果它不起作用, 它会以正常的方式装入 html 代码, 忽略隐藏功能 : 该怎么办?

    <script type="text/javascript">
        $(function() {
            var tot = $(".slide").length,
            current = 1

            $(".slide").not(":first").hide()

            $("#next").click(function () {
            if (current+1 > tot) return false

            $(".slide:visible").hide().next().show()
            current++
            })

            $("#prev").click(function () {
            if (current-1 < 1) return false

            $(".slide:visible").hide().prev().show()
                current--
            })
        })​
    </script>

    <div id="slide_container">  
            <div class="slide">
                <p>Step 1 explained</p>
                <img src="images/android.png" border="none"/>
            </div>
            <div class="slide">
                <p>Step 2 Explained</p>
                <img src="images/apple.png" border="none"/>
            </div>
            <div class="slide">
                <p>Step 3 explained</p>
                <img src="images/windows.png" border="none"/>
            </div>
            <div>
                <button id="prev">Prev</button>
                <button id="next">Next</button> 
            </div>
    </div>

谢谢!

问题回答

我重新编排了你的代码,并添加了几个分号 < code> ; 清晰度,我还修改了当前和总体的索引编制,似乎所有都有效,我创建了一个 < href=>" http://jsfiddle.net/NL7EJ/" rel=“nofollow”>jsFiddle , 使用下面的 JavaScript, 似乎都工作正常。请试一下 。

$(function()
{
    var total = $(".slide").length;
    var current = 0

    $(".slide").not(":first").hide()

    $("#next").click(function ()
    {
        if (current + 1 >= total)
        {
            return false;
        }

        $(".slide:visible").hide().next().show();
        current++
    })

    $("#prev").click(function ()
    {
        if (current <= 0)
        {
            return false;
        }

        $(".slide:visible").hide().prev().show();
        current--;
    });
})​

我希望你在这里提供的剧本块之前 加上Jquery的参考词 只是一个想法





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签