【发布时间】:2015-01-20 02:44:51
【问题描述】:
我需要一个按钮 onclick 来显示内容,同时它也将 target="_blank" 一个新窗口...有可能吗? 我尝试了一些代码但无法正常工作,有人可以帮我解决这个问题吗? 谢谢大家!
<style type="text/css">
/* This CSS is used for the Show/Hide functionality. */
.more {
display: none;
border-top: 1px solid #666;
border-bottom: 1px solid #666; }
a.showLink, a.hideLink {
text-decoration: none;
color: #36f;
padding-left: 8px;
background: transparent url(down.gif) no-repeat left; }
a.hideLink {
background: transparent url(up.gif) no-repeat left; }
a.showLink:hover, a.hideLink:hover {
border-bottom: 1px dotted #36f; }
</style>
<div id="wrap">
<h1>Show/Hide Content</h1>
<a href="https://www.facebook.com/sharer/sharer.php?app_id=309437425817038&sdk=joey&u=http%3A%2F%2Fcloudsblack.com%2F180115f.html&display=popup&ref=plugin"
id="example-show" class="showLink" onclick="showHide('example');return false;">
<button class="btn-u btn-u-lg btn-block btn-u-dark-blue">
<i class="fa fa-facebook"></i> Facebook
</button>
</a>
<div id="example" class="more">
<p>Congratulations! You've found the magic hidden text! Clicking the link below will hide this content again.</p>
<p><a href="#" id="example-hide" class="hideLink" onclick="showHide('example');return false;">Hide this content.</a></p>
</div>
</div>
<!-- Hide Function -->
<script language="javascript" type="text/javascript">
function showHide(shID) {
if (document.getElementById(shID)) {
if (document.getElementById(shID+'-show').style.display != 'none') {
document.getElementById(shID+'-show').style.display = 'none';
document.getElementById(shID).style.display = 'block';
}
else {
document.getElementById(shID+'-show').style.display = 'inline';
document.getElementById(shID).style.display = 'none';
}
}
}
</script>
【问题讨论】:
-
为什么不在函数中处理新窗口的打开?通过在 onclick 函数上返回 false,您将停止对该事件的正常传播。
-
对不起,我是 Javascript 新手,你能教我怎么做吗?
标签: javascript button onclick show-hide