我編寫(xiě)了一個(gè) javascript 函數(shù),它根據(jù)單擊哪個(gè)按鈕更改元素的背景圖像。所有圖像都存儲(chǔ)在一個(gè)單獨(dú)的文件夾中。它在 localhost 之外正常工作,但是當(dāng)我在 localhost 上運(yùn)行該頁(yè)面時(shí),該特定功能不再有效,所有其他 javascript 功能都正常工作。我還沒(méi)有在那個(gè)頁(yè)面上實(shí)現(xiàn) php,所以我不確定問(wèn)題出在哪里。function changeBG(btnID){ var card = document.getElementById('edit'); if(btnID == 'btn1') card.style.backgroundImage = "url('/images/1.JPG')"; else if(btnID == 'btn2') card.style.backgroundImage = "url('/images/2.jpg')"; else if(btnID == 'btn3') card.style.backgroundImage = "url('/images/3.jpg')"; else if(btnID == 'btn4') card.style.backgroundImage = "url('/images/4.jpg')";}.cardImage{ height: 15rem; width: 30rem; border-radius: 30px; background: #a4bac0; background-image: url(''); background-position: center;}<div class="cardImage" id="edit"> <h5>Card</h5></div><div class="options"> <h6>Options</h6> <button class="op" id="btn1" onclick="changeBG(this.id);">1</button> <button class="op" id="btn2" onclick="changeBG(this.id);">2</button> <button class="op" id="btn3" onclick="changeBG(this.id);">3</button> <button class="op" id="btn4" onclick="changeBG(this.id);">4</button> <button class="op" id="save">Save</button></div>
某些 Javascript 函數(shù)不適用于 WAMP
ABOUTYOU
2023-03-03 13:11:40