小编典典

JavaScript隐藏/显示元素

javascript

按下后如何隐藏“编辑”链接?当我按下编辑键时,是否还可以隐藏“ lorem ipsum”文本?

<script type="text/javascript">
function showStuff(id) {
  document.getElementById(id).style.display = 'block';
}
</script>


<td class="post">

  <a href="#" onclick="showStuff('answer1'); return false;">Edit</a>
  <span id="answer1" style="display: none;">
    <textarea rows="10" cols="115"></textarea>
  </span>

  Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum 
</td>

阅读 432

收藏
2020-04-25

共1个答案

小编典典

function showStuff(id, text, btn) {

    document.getElementById(id).style.display = 'block';

    // hide the lorem ipsum text

    document.getElementById(text).style.display = 'none';

    // hide the link

    btn.style.display = 'none';

}


<td class="post">



<a href="#" onclick="showStuff('answer1', 'text1', this); return false;">Edit</a>

<span id="answer1" style="display: none;">

<textarea rows="10" cols="115"></textarea>

</span>



<span id="text1">Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</span>

</td>
2020-04-25