I am really new to javascript and struggling big with it. The code i have is below. It's easier to explain with more code. So basically want to show each image in each placeholder but in the order i click them in. So if i click img 3 this will go to placeholder 1 then the next one i click will go to placeholder 2 if that makes sense. (this tricky bit is once one option has been chosen i want to not allow that option again. either with an error message saying already used or disappear from list)
<script type="text/javascript" language="jav开发者_如何学JAVAascript">
function showPic (whichpic) {
if (document.getElementById) {
document.getElementById('placeholder1').src = whichpic.href;
document.getElementById('placeholder2').src = whichpic.href;
document.getElementById('placeholder3').src = whichpic.href;
if (whichpic.title) {
document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
} else {
document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
}
return false;
} else {
return true;
}
}
</script>
<div style="border: 1px solid #999; padding: 1em; margin: 0 0 15px 0;">
<ul>
<li><a onclick="return showPic(this)" href="images/img1.jpg" title="img 1">img 1</a></li>
<li><a onclick="return showPic(this)" href="images/img2.jpg" title="img 2">img 2</a></li>
<li><a onclick="return showPic(this)" href="images/img3.jpg" title="img 3">img 3</a></li>
</ul>
<p id="desc">Choose an image to begin</p>
<img id="placeholder1" src="images/blank.gif" alt="" />
<img id="placeholder2" src="images/blank.gif" alt="" />
<img id="placeholder3" src="images/blank.gif" alt="" />
</div>
That depends on what you mean by "something from the list". If you just want to check if the src is blank, you can do a direct conditional:
if (document.getElementById('placeholder1').src != '')
document.getElementById('placeholder2').src = newurl;
something along the lines of this?
http://jsfiddle.net/UpeFT/1/
bit messy though :P
精彩评论