我想使用所单击的链接中的名称以显示在 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 bestelknop 中显示当前链接的名称。
我是 javascript 新手,所以请帮助我。
问候,
本尼
最佳答案
您可以将当前链接传递给该函数。
在这里查看我的工作示例: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;
}
关于javascript - 获取链接名称并将其写在 div 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16681194/