所以我到底要的是,當我把我的密碼變量更改爲其他頁面上的圖片,這是我的代碼:PAGE 1如何將圖像從一個html頁面更改爲另一個?
<html>
<title>page 1</title>
<head><link rel="stylesheet" type="text/css" href="csspage.css">
<script type="text/javascript">
var number;
var pin = "";
function change(){
if (pin == "1234") {
window.open("page2.html", "_self");
}
if (pin="2345") {
window.open("page2.html", "_self");
}
<body>
<input type="password" id="password"/>
</body>
</html>
這工作正常,但我一直在努力使第二次ping如果引腳爲"2345"
,則從頁面2更改一個圖像。這是我試過的代碼:
if (pin="2345") {
window.open("page2.html", "_self");
document.getElementById("photo").src="page2.html".setAttribute("style","display:none");
document.getElementById("photo2").src="page2.html".setAttribute("style","display:block");
的目的是,如果該引腳是一個展示從一個人一張圖片,如果引腳是它的另一個變化的其他用戶,但需要從改變PIC頁面1.我能做到這一點的任何方式?
@ manelgarcia的建議是正確的,但也是這個'document.getElementById(「photo」)。src =「page2.html」.setAttribute(「style」,「display:none」);'是不正確的語法。你可以刪除'src = ...'部分,只保留'setAttribute'。目前還不清楚這些網頁與您的問題中的圖片相關。 – RecencyEffect
那我怎麼從page2上得到照片呢?他們有共同的css –
如果圖像位於不同的html頁面,你不能,這是不可能的。考慮在同一頁面上包括兩個圖像,並根據需要隱藏/顯示它們。 – RecencyEffect