Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/411.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何让不同的图像和文本自动循环?我的图像在循环,但我的文本不是';T_Javascript - Fatal编程技术网

Javascript 如何让不同的图像和文本自动循环?我的图像在循环,但我的文本不是';T

Javascript 如何让不同的图像和文本自动循环?我的图像在循环,但我的文本不是';T,javascript,Javascript,我在一个页面上工作,需要循环浏览带有相应图像描述的图像。我可以让图像循环浏览,但我的文本没有任何作用。我的功能可能有点不对劲,我从来没有尝试过同时循环图像和文本。任何帮助都将不胜感激!这是我的密码: <!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

我在一个页面上工作,需要循环浏览带有相应图像描述的图像。我可以让图像循环浏览,但我的文本没有任何作用。我的功能可能有点不对劲,我从来没有尝试过同时循环图像和文本。任何帮助都将不胜感激!这是我的密码:

<!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" />
        <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 = new Array();
            curImage[0] = "tool1";
            curImage[1] = "tool2";
            curImage[2] = "tool3";
            curImage[3] = "tool4";
            curImage[4] = "tool5";

            var curInfo = new Array();
            curInfo[0] = "info1";
            curInfo[1] = "info2";
            curInfo[2] = "info3";
            curInfo[3] = "info4";
            curInfo[4] = "info5";

            function toolPics() {
                if (curImage == "tool1") {
                    document.images[0].src = "images/ladder.jpg";
                    curImage = "tool2";
                    if (curInfo == "info1") {
                    document.getElementsByTagName("p")[2].style.display = "none";
                    curInfo = "info2";
                    }
                }
                else if (curImage == "tool2") {
                    document.images[0].src = "images/impacter.jpg";
                    curImage = "tool3";
                    if (curInfo == "info2") {
                    document.getElementsByTagName("p")[3].style.display = "none";
                    curInfo = "info3";
                    }
                }
                else if (curImage == "tool3") {
                    document.images[0].src = "images/saw.jpg";
                    curImage = "tool4";
                    if (curInfo == "info3") {
                    document.getElementsByTagName("p")[4].style.display = "none";
                    curInfo = "info4";
                    }
                }
                else if (curImage == "tool4") {
                    document.images[0].src = "images/mower.jpg";
                    curImage = "tool5";
                    if (curInfo == "info4") {
                    document.getElementsByTagName("p")[5].style.display = "none";
                    curInfo = "info5";
                    }
                }
                else {
                    document.images[0].src = "images/toolkit1.jpg";
                    curImage = "tool1";
                    document.getElementsByTagName("p")[1].style.display = "block";
                    curInfo = "info1";
                }
            }
        /* ]]> */
        </script>
    </head>
    <body onload="var begin=setInterval('toolPics()', 5000);">
        <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>At <em style="color:red">Collin's Tool Supply</em>, we believe that every home should be in possesion of a few necessary tools. These tools will help the average person tackle most projects around the house that do not call for a professional. Take a look and make sure your home is prepared for the quick fix.
        </div>
        <div>
            <table>
                <tr>
                    <td><img src="images/toolkit1.jpg" alt="Tool Kit" /></td>
                    <td><p id="description1" style="display: block"><strong>Description:</strong> The Craftsmen Tool Kit offers 119 different tools to tackle most of your smaller repairs around the house. A must have in every home!<br />
                    <strong>Items Included:</strong> 3/8 in. Ratchet Handle, 3/8 in. x 6 in. Extension Bar, 3/8 in. to 1/4 in. Adapter, 3/8 in Socket Set, 1/4 in. x 3 in. Extension Bar, 1/4 in. Socket Set, Combination Wrenches Set, 3/8 in Spark Plug Socket, Screwdrivers, 6 in. Long Nose Pliers, 6 in. Diagonal Pliers, 6 in Adjustable Wrench, Hex Key Set, Screwdriver Bits, Ratchet Screwdriver, 1/4 in. Adapter, 1/4 in. Bit Holder, 16 oz. Hammer, Torpedo Level, 16 in. Tape Measure, Storage Case<br />
                    <strong>Price:</strong> $32.99</p>
                    <p id="description2" style="display: none"><strong>Description:</strong> Werner 6ft fiberglass step ladder. Used to help change light bulbs, reach items on top of your refrigerator, paint walls and ceilings, turn on ceiling fans, the list goes on and on.<br />
                    <strong>Price:</strong> $59.00</p>
                    <p id="description3" style="display: none"><strong>Description:</strong> Makita impact driver. Use this powerful, cordless drill to put together household items like tables, chairs, bed frames, kids toys, etc. Also great for hanging blinds, window treatments, and wall decorations. No pre-drilling with this powerful drill.<br />
                    <strong>Price:</strong> $179.99</p>
                    <p id="description4" style="display: none"><strong>Description:</strong> Dewalt 7inch circular saw. Cuts 2 x 4 with ease. Throw that hand saw away and save yourself some time and back ache.<br />
                    <strong>Price:</strong> $169.99</p>
                    <p id="description5" style="display: none"><strong>Description:</strong> Toro recycler self-propelled lawn mower. Keep your lawn in prestine condition with this easy to use lawn mower. It is self-propelled to make life a little easier on whoever is cutting the grass.<br />
                    <strong>Price:</strong> $329.99</p>
                    </td>
                </tr>
            </table>
    </body>
</html>

/*  */
|
|
|
|
在科林的工具供应处,我们相信每个家庭都应该拥有一些必要的工具。这些工具将帮助普通人处理家中大多数不需要专业人员的项目。看一看,确保你的家准备好了快速修复。

说明:工匠工具包提供119种不同的工具,用于处理房屋周围的大部分小型维修。每家每户都必须有一个
包括的项目:3/8英寸。棘轮手柄,3/8英寸。x 6英寸。加长杆,3/8英寸。到1/4英寸。适配器,3/8英寸插座组,1/4英寸。x3英寸。加长杆,1/4英寸。套筒套件,组合扳手套件,3/8英寸火花塞套筒,螺丝刀,6英寸。长嘴钳,6英寸。对角钳,6英寸可调扳手,六角扳手组,螺丝刀头,棘轮螺丝刀,1/4英寸。适配器,1/4英寸。钻头支架,16盎司锤,鱼雷水平,16英寸。卷尺、存储盒
价格:32.99美元

说明:Werner 6英尺玻璃纤维阶梯。用于帮助更换灯泡、接触冰箱顶部的物品、粉刷墙壁和天花板、打开吊扇,清单不胜枚举。
价格:59.00美元

说明:Makita碰撞驱动程序。使用这种功能强大的无绳电钻,可以将桌子、椅子、床架、儿童玩具等家居用品放在一起。同样适用于悬挂百叶窗、窗饰和墙壁装饰。无需使用此强力钻进行预钻孔。
价格:179.99美元

说明:脱蜡7英寸圆锯。轻松切割2 x 4。扔掉那把手锯,省点时间和背部疼痛。
价格:169.99美元

说明:Toro recycler自行式割草机。使用这款易于使用的割草机,让您的草坪保持预紧状态。无论是谁割草,它都是自动推进的,让生活变得更轻松。
价格:329.99美元


如果我理解您试图正确执行的操作,则您似乎需要通过设置
style.display=“none”
来隐藏以前的描述,但为了显示当前描述,您必须为该元素设置
style.display=“block”

尝试以下方法:

if (curImage == "tool1") {
    document.images[0].src = "images/ladder.jpg";
    curImage = "tool2";
    if (curInfo == "info1") {

        // hide the previous description
        document.getElementsByTagName("p")[1].style.display = "none";

        // display the current description
        document.getElementsByTagName("p")[2].style.display = "block";

        curInfo = "info2";
    }
}

谢谢你,加里!这就是问题所在对不起,我对这个网站不熟悉。我接受了答案,再次感谢你的帮助!