繁体   English   中英

Onclick 仅适用于第二次点击。 如何让它在第一次点击时工作

[英]Onclick only works on second click. How to get it to work on first click

有没有办法让 onclick 在第一次点击时工作? 我在同一页面上有多个实例。 这是我的代码:

<script>
function showMoreOrLess(thisObj) {
  var caption = thisObj.innerHTML;
  var otherObj = thisObj.parentElement.previousElementSibling;
  if (caption == "Read more") {
    otherObj.style.display = "inline";
    thisObj.innerHTML = "Read less";
  } else {
    otherObj.style.display = "none";
    thisObj.innerHTML = "Read more";
  } 
} 
</script>
<p><a onclick="showMoreOrLess(this);">Read more </a></p> 

删除空间

<a onclick="showMoreOrLess(this);">Read more </a>

<a onclick="showMoreOrLess(this);">Read more</a>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM