我有一个Javascript函数可以在点击时打开一个隐藏的div,但我还要删除/隐藏点击按钮。我知道这是可能的,但我无法弄清楚。
<span id="first_related">
content 1
</span>
<span id="second_related" style="display:none;">
content 2 hidden / display on click
</span>
<div class="clear"></div>
<div class="btn">
<input id="current_page_viewed_videos" type="hidden">
<input type="hidden" id="related_videos_delta"><a onclick="showDiv()">Show More</a>
</div>
<script type="text/javascript">
function showDiv() {
document.getElementById('second_related').style.display = "block";
document.getElementById('open').style.display = "none";
}
</script>
谢谢!
答案 0 :(得分:1)
您的Javascript没问题,您需要的只是添加num=input()
:
<button id="open" onclick="showDiv()">click</button>
&#13;
function showDiv() {
document.getElementById('second_related').style.display = "block";
document.getElementById('open').style.display = "none";
}
&#13;
有关更新的问题:
<span id="first_related">
content 1
</span>
<span id="second_related" style="display:none;">
content 2 hidden / display on click
</span>
<button id="open" onclick="showDiv()">click</button>
&#13;
function showDiv() {
document.getElementById('second_related').style.display = "block";
document.getElementById('open').style.display = "none";
}
&#13;
答案 1 :(得分:0)
使用jquery这可能很简单。给你一个id的按钮(例如id =&#39; mybutton&#39;), 然后在你的代码中显示div add: $(&#39;#myButton的&#39)。隐藏()