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>

回答:

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>

以上是 JavaScript隐藏/显示元素 的全部内容, 来源链接: utcz.com/qa/401709.html

回到顶部