1

画像をループさせることができましたが、「前へ」または「次へ」のリンクをクリックすると、画像が保存されているファイル フォルダーが毎回ポップアップします。なぜこれが起こっているのか、またはそれを止める方法について何か考えはありますか?

スクリプト

<script type="text/javascript">
            /* <![CDATA[ */
                function changeDisplay(curLine) {
                    curLine.style.color = "red";
                    curLine.style.fontWeight = "bold";
                }

                function restoreDisplay(curLine) {
                    curLine.style.color = "blue";
                    curLine.style.fontWeight = "normal";
                }

                var curImage = 1;

                function changeImage(which) {
                    for (var i=0; i < 5; ++i) {
                        document.getElementById("image"+i).style.display = "none";
                    }
                    if (which < 1) 
                        which = 5;
                    if (which > 5)
                        which = 1;
                    document.getElementById("image"+which).style.display = "block";
                    curImage = which;
                }
            /* ]]> */
            </script>

HTML

     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
        <link type="text/css" rel="stylesheet" href="project.css" />

    </head>
    <body>
        <div>
            <table style="border:none" class="menu">
                <tr>
                    <td><a href="Index.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Home</a></td>
                    <td class="menupipe">|</td>
                    <td><a href="Specials.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Specials</a></td>
                    <td class="menupipe">|</td>
                    <td><a href="Tools.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Tools</a></td>
                    <td class="menupipe">|</td>
                    <td><a href="Prices.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Prices</a></td>
                    <td class="menupipe">|</td>
                    <td><a href="Order.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Shop</a></td>
                </tr>
            </table>
        </div>
        <div>
            <p style="font-weight:bold; font-size:20px">With winter approaching, every homeowner wants to be prepared for the snow and ice! We are now running a sale on a few items that will help handle the harsh winter conditions. Take a look at our prices and make sure you stock up. Click on the images below for more information.</p>
        </div>
        <div id="image" style="display:block">
            <img src="images/deicer.jpg" height="300" width="300" alt="deicer" />
        </div>
        <div id="image" style="display:none">
            <img src="images/snowblower.jpg" height="300px" width="300px" alt="snowblower" />
        </div>
        <div id="image" style="display:none">
            <img src="images/icemelt.jpg" height="300px" width="250px" alt="icemelt" />
        </div>
        <div id="image" style="display:none">
            <img src="images/shovel.jpg" height="225px" width="225px" alt="shovel" />
        </div>
        <div id="image" style="display:none">
            <img src="images/scraper.jpg" height="124" width="124" alt="scraper" />
        </div>
        <button type="button" onclick="changeImage(curImage - 1)">Previous</button>
        <button type="button" onclick="changeImage(curImage + 1)">Next</button> 
    </body>
</html>
4

3 に答える 3

2

次のように、すべての画像 div にインデックス (1 - 5) を追加します。

<div id="image1" style="display:block">

ループ内のインデックスも変更して、どこでも持つようにします1 - 5。または、すべてを に変更します0 - 4

于 2013-10-16T04:16:40.477 に答える
2

すべてのイメージ コンテナー

<div id="image" style="display:none">

同じIDを持ち、フォーマット画像に対応していません#

また、次のループを

for (var i=0; i < 5; ++i) {
     document.getElementById("image"+i).style.display = "none";
    }

for (var i=0; i < 5; ++i) {
         document.getElementById("image"+ (i + 1)).style.display = "none";
        }
于 2013-10-16T04:17:48.213 に答える
0

各画像コンテナに 1,2,3,4 を追加することで動作するようになりました..

私のバージョンは以下です

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
        <link type="text/css" rel="stylesheet" href="project.css" />
        <script type="text/javascript">
        /* <![CDATA[ */
            function changeDisplay(curLine) {
                curLine.style.color = "red";
                curLine.style.fontWeight = "bold";
            }

            function restoreDisplay(curLine) {
                curLine.style.color = "blue";
                curLine.style.fontWeight = "normal";
            }

            var curImage = 1;

            function changeImage(which) {
                for (var i=0; i < 5; ++i) {
                    document.getElementById("image"+i).style.display = "none";
                }
                if (which < 1) 
                    which = 5;
                if (which > 5)
                    which = 1;
                document.getElementById("image"+which).style.display = "block";
                curImage = which;
            }
        /* ]]> */
        </script>
    </head>
    <body>
        <div>
            <table style="border:none" class="menu">
                <tr>
                    <td><a href="Index.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Home</a></td>
                    <td class="menupipe">|</td>
                    <td><a href="Specials.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Specials</a></td>
                    <td class="menupipe">|</td>
                    <td><a href="Tools.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Tools</a></td>
                    <td class="menupipe">|</td>
                    <td><a href="Prices.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Prices</a></td>
                    <td class="menupipe">|</td>
                    <td><a href="Order.html" class="menuicon" onmouseover="changeDisplay(this)" onmouseout="restoreDisplay(this)">Shop</a></td>
                </tr>
            </table>
        </div>
        <div>
            <p style="font-weight:bold; font-size:20px">With winter approaching, every homeowner wants to be prepared for the snow and ice! We are now running a sale on a few items that will help handle the harsh winter conditions. Take a look at our prices and make sure you stock up. Click on the images below for more information.</p>
        </div>
        <div id="image0" style="display:block">
            <img src="http://placehold.it/350/ffffff/000000">
        </div>
        <div id="image1" style="display:none">
            <img src="http://placehold.it/350/ffffff/000000">
        </div>
        <div id="image2" style="display:none">
            <img src="http://placehold.it/350/ffffff/000000">
        </div>
        <div id="image3" style="display:none">
            <img src="http://placehold.it/350/ffffff/000000">       
        </div>
        <div id="image4" style="display:none">
            <img src="http://placehold.it/350/ffffff/000000">
        </div>
        <button type="button" onclick="changeImage(curImage - 1)">Previous</button>
        <button type="button" onclick="changeImage(curImage + 1)">Next</button> 
    </body>
</html>
于 2013-10-16T04:23:15.633 に答える