onclick return and javascript

onclick return and javascript

本文关键字:javascript and return onclick      更新时间:2023-09-26

感谢任何能帮助我的人!

我有一段文字,代码是:

<a onclick="return showPic(this); mostrarespectacular()" href="Imatges/productosnuevos/urbano01.jpg">&nbsp Circuito Espectacular Barcelona</a>

脚本是:

<script type="text/javascript">
function showPic (whichpic) {
 if (document.getElementById) {
  document.getElementById('imgContenedor').src = whichpic.href;
  if (whichpic.title) {
      document.getElementById('imgDescripcion').childNodes[0].innerHTML = whichpic.innerHTML;
  }
  return false;
 } else {
  return true;
 }
}
</script>
<script type="text/javascript">
function mostrarespectacular() {
    div = document.getElementById('circuloespectacular');
    div.style.display = 'inline';
}
function cerrarespectacular() {
    div = document.getElementById('circuloespectacular');
    div.style.display='none';
}
</script>

我的问题是,第一个函数运行得很好,但第二个函数(必须显示div)运行得不好。你知道我做错了什么吗?谢谢

在第一次函数调用后从onclick返回。去掉它,你就应该没事了。

"return"是在调用showPic()函数后从脚本中分支出来的。删除return或将其放在"mostrarespectacular()"调用之前,或将其移动到末尾,等等。