Javascript placeholders [duplicate]
Possible Duplicate:
Javascript placeholders
Erm.. i 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="javascript">
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>
You can remove the <li>
like this. After:
if (whichpic.title) {
document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
} else {
document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
}
And before:
return false;
Add:
var node = whichpic;
while(node.nodeName != 'LI' && (node = node.parentNode));
node.parentNode.removeChild(node);
精彩评论