第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

圖片正在加載為空

圖片正在加載為空

UYOU 2021-05-08 17:13:45
我是Java語(yǔ)言的新手,但我嘗試使用onload()設(shè)置默認(rèn)圖像,但我認(rèn)為它無(wú)法達(dá)到我在數(shù)組中設(shè)置的圖像,因此我不知道為什么。單擊按鈕后,我將使它旋轉(zhuǎn)圖像,但是我什至無(wú)法獲得要添加的默認(rèn)圖像。var images = ['img/profile.jpg', 'img/mountain.jpg', 'img/sanfran.jpg'];var num=1;function loadPage(){    document.getElementById("pictures").src = images[0].src;}function nextImage(pictures){    var img = document.getElementById("pictures");    document.getElementById("pictures").src = images[1].src;    console.log(num++); // I have this just to make sure that it is catching something}<div id="maincontent">  <div id="pictures">     <img src="img/mountain.jpg">  </div>  <div id="paragraph">    <p>    </p>    <button onclick="nextImage()">Switch Images</button>  </div></div>
查看完整描述

3 回答

?
Smart貓小萌

TA貢獻(xiàn)1911條經(jīng)驗(yàn) 獲得超7個(gè)贊

這里的圖像是一個(gè)javascript數(shù)組。因此,您不能使用.src,因?yàn)樗皇荋TML img元素


var images = ['img/profile.jpg', 'img/mountain.jpg', 'img/sanfran.jpg'];

var num=1;


//This function will run on body onload

function loadPage()

{

    document.getElementById("pictures").src = images[0];

}


//This function will run on button click

function nextImage()

{

    var img = document.getElementById("pictures");

    document.getElementById("pictures").src = images[1];

    console.log(num++); // I have this just to make sure that it is catching something

}

<body onload="loadPage()">

    <div id="maincontent">

        <img id="pictures" src="img/mountain.jpg">

        <div id="paragraph">

            <p>

            </p>

            <button onclick="nextImage()">Switch Images</button>

        </div>

    </div>

</body>


查看完整回答
反對(duì) 回復(fù) 2021-05-20
?
湖上湖

TA貢獻(xiàn)2003條經(jīng)驗(yàn) 獲得超2個(gè)贊

試試這個(gè):


<script>

var images = ['img/profile.jpg', 'img/mountain.jpg', 'img/sanfran.jpg'];

var num=0;


function loadPage()

{

    document.getElementById("pictures").src = images[0].src;

}


function nextImage(pictures)

{

    if(num<images.length-1) {

        num = num+1;

    } else {

    num = 0;

    }


    var img = document.getElementById("pictures");

    document.getElementById("pictures").src = images[num];

    console.log(num); // I have this just to make sure that it is catching something

}

</script>

<div onload="loadPage()">

  <div id="imageholder">

     <img id="pictures" src="img/mountain.jpg">

  </div>

  <div id="paragraph">

    <p>

    </p>

    <button onclick="nextImage()">Switch Images</button>

  </div>

</div>


查看完整回答
反對(duì) 回復(fù) 2021-05-20
  • 3 回答
  • 0 關(guān)注
  • 193 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)