2014-04-04 28 views
0

我正在開發一個有4個級別和主頁的遊戲。在主頁上,用戶通過選擇一個單選按鈕選擇4個圖像中的一個(本頁有4個圖像)。這個選定的圖像應該顯示在所有的水平(像你可以說的個人資料圖片)。但是當用戶在任何一個關卡中擊敗他時(他顯然應該能夠選擇新圖像),並且所選圖像將不再顯示。使用HTML和javascript在許多HTML頁面上顯示個人資料圖片

Iam僅在HTML和JavaScript中開發此遊戲。是否有可能在HTML和JavaScript?如果沒有,那麼我知道非常非常基礎的PHP,如果它是可以使用PHP實現的。

<input type="radio" name="profile" value="boy1" style="margin-left:40px;" onclick="location.href = 'firsta.html';"> 
<img style="margin-left:25px;" src="boy01.png" width="200" height="200" /> 

<input type="radio" name="profile" value="boy2" style="margin-left:40px;" onclick="location.href = 'firsta.html';"> 
<img style="margin-left:25px;" src="boy02.png" width="200" height="200" /> 

<input type="radio" name="profile" value="girl1" style="margin-left:40px;" onclick="location.href = 'firsta.html';"> 
<img style="margin-left:25px;" src="girl01.png" width="200" height="200" /> 

<input type="radio" name="profile" value="girl2" style="margin-left:40px;" onclick="location.href = 'firsta.html';"> 
<img style="margin-left:25px;" src="girl02.png" width="200" height="200" /> 
+0

請提供代碼等信息。 http://stackoverflow.com/help/how-to-ask – Seth

回答

0

您可以設置所選圖像的文件名到localStorage的(或餅乾),然後又看了一遍,當你想使用它。

<input type="radio" name="profile" value="boy1.png" style="margin-left:40px;" onclick="chooseProfile(this.value, 'firsta.html')"> 
<img style="margin-left:25px;" src="boy01.png" width="200" height="200" /> 

在你的JavaScript:

function chooseProfile(img, page) { 
    localStorage.profilePic = img; 
    location.href = page; 
} 

然後,當你想閱讀:

document.getElementById('profileImage').src = localStorage.profilePic; 
+0

當我檢索使用document.getElementById IAM無法看到我的下一頁上的圖像。但是,當我使用警報框時,圖像值顯示。所以價值被傳遞到下一頁,但不顯示。 – sandeep007

+0

您需要在html中首先添加一個佔位符圖像,其ID爲「profileImage」。例如'profile picture' – Akurn

+0

非常感謝。很高興再次感謝您的好評:D – sandeep007

相關問題