我希望使用链接中的名称,该链接被单击以显示在div中。我试了很多方法,但什么也没做。我还有一个小脚本来显示和隐藏一个div,在我尝试为该名称创建一个脚本之前,它工作得很好。有没有人能快速看一眼。
//script for hiding and display div
function showDiv() {
document.getElementById('popup').style.display = "block";
}
function hideDiv() {
document.getElementById('popup').style.display = "none";
}和html:
<div class="maintab">
<div class="tab" onclick="showDiv()" ><a href="#">Template</a></div>
</div>
<div id="bestelknop">**Here the name must come**</div>
<div id="popup" style="display:none">
<ul>
<a href="http://pixelweb.be" target="iframe" onclick="hideDiv()" name="Pixelweb">pixelweb</a>
<a href="http://templates.pixelweb.be/social" target="iframe" onclick="hideDiv()" name="Social">social</a>
<a href="http://templates.pixelweb.be" target="iframe" onclick="hideDiv()" name="Templates" >templates pixelweb</a>
</ul>
</div>现在我想要在div want旋钮中显示name van de current链接。
我是javascript中的newbee,所以请帮我解决这个问题。
致以敬意,
本尼
发布于 2013-05-22 07:53:29
您可以将当前链接传递给函数。
看一下我这里的工作示例:http://jsfiddle.net/XfW3P/
<div class="maintab">
<div class="tab" onclick="showDiv()" ><a href="#">Template</a></div>
</div>
<div id="bestelknop">**Here the name must come**</div>
<div id="popup" style="display:none">
<ul>
<a href="http://pixelweb.be" target="iframe" onclick="hideDiv(this)" name="Pixelweb">pixelweb</a>
<a href="http://templates.pixelweb.be/social" target="iframe" onclick="hideDiv(this)" name="Social">social</a>
<a href="http://templates.pixelweb.be" target="iframe" onclick="hideDiv(this)" name="Templates" >templates pixelweb</a>
</ul>
</div>JavaScript代码:
function showDiv() {
document.getElementById('popup').style.display = "block";
}
function hideDiv(link) {
document.getElementById('popup').style.display = "none";
document.getElementById('bestelknop').innerHTML = link.name;
}发布于 2013-05-22 07:53:45
首先,在每个链接中将this传入您的`onclick="hideDiv(this)“:
<a href="http://pixelweb.be" target="iframe" onclick="hideDiv(this)" name="Pixelweb">pixelweb</a>
<a href="http://templates.pixelweb.be/social" target="iframe" onclick="hideDiv(this)" name="Social">social</a>
<a href="http://templates.pixelweb.be" target="iframe" onclick="hideDiv(this)" name="Templates" >templates pixelweb</a>然后,更改您的hideDiv()函数:
function hideDiv(obj) {
document.getElementById('popup').style.display = "none";
document.getElementById('bestelknop').innerHTML = obj.name + " " + obj.href;
}小提琴:http://jsfiddle.net/bUVtA/
https://stackoverflow.com/questions/16681194
复制相似问题