因此,如果爲此提供適當的標題,我會遇到一些麻煩,所以請在輸入時糾正我的錯誤。將圖片和文字設爲默認
點擊我的問題(我添加了一張圖片以供澄清)當我點擊按鈕1時,圖片將顯示在左側,文本將顯示在中間。如果點擊按鈕2,新圖片將顯示在左側,並且新的文本將顯示在中間。
所以我的問題是:如何將按鈕1設置爲默認值,以便在加載網站時顯示與該按鈕相關的圖片和文本。即時通訊新的JS,所以請詳細解釋。謝謝。 ![[
function changeText(value) {
var div = document.getElementById("div");
var text = "";
var image = "";
if (value == 1) text += "<span class='custom_text_h_w'>this is picture one</span> <br> <img class='custom_h_w' src='images/consumers_1.png'/>";
if (value == 2) text += "<span class='custom_text_h_w'>this is picture two</span> <br> <img class='custom_h_w' src='images/consumers_2.png'/>";
if (value == 3) text += "<span class='custom_text_h_w'>this is picture tree</span> <br> <img class='custom_h_w'src='images/consumers_3.png'/>";
div.innerHTML = text;
}
.custom_h_w{
top: 1700px;
left: 100px;
height:456px;
width: 342px;
position: absolute;
}
.custom_text_h_w{
top: 1700px;
right: 800px;
position: absolute;
}
<a href="javascript: changeText(1);">
<img id="searchconsumers" src="images/search.png" width="60px" height="60px" alt="abc" />
</a>
<a href="javascript: changeText(2);">
<img id="exploreconsumers" src="images/explore.png" width="60px" height="60px" top="1700px" right="700px" alt="abc" />
</a>
<a href="javascript: changeText(3);">
<img id="funconsumers" src="images/fun.png" width="60px" height="60px" alt="abc" />
</a>
<div id="div"></div>
<體的onload = 「changeText(1);」>一團糟我的一些其它碼和document.addEventListener( 'DOMContentLoaded',函數(){ changeText(1); }你也有同樣的建議嗎?你有其他建議嗎? –