如何让这个jQuery文本消失? [英] How do I make this jQuery text disappear?

查看:131
本文介绍了如何让这个jQuery文本消失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我是一名学生,在我的编码课上非常迷失。我的老师给了我们这个代码来实现这一点,当我点击一个标题时,它会扩展为一个段落。

So I'm a student and just very lost in my coding class. My teacher gave us this code to make it so when I click on a header, it expands into a paragraph.

然后他希望我们在你点击时这样做标题,段落再次消失。我只是无法弄清楚如何做第二部分,使它消失。

He then wants us to make it so when you click on the header, the paragraph disappears again. I just cannot figure out how to do this second part, making it disappear.

这就是显示文章代码的样子。

This is what the 'Show Article' code looks like.

function showArticle(id) {
  document.getElementById(id).style.display="block";

有人可以帮帮我吗?我觉得这很简单,我对此非常不满意。如果你能告诉我在我的代码中将它放在哪里也会非常感激。

Can anyone help me out please? I feel like it's so simple I'm just so bad at this. If you could tell me where to place it in my code that would be much appreciated as well.

推荐答案

如果你正在使用js而不是jquery

If you are using js and not jquery

var visible = false;
function showArticle(id) {
  if (visible === false) {
    document.getElementById(id).style.display="block";
    visible = true;
  }
  else {
    document.getElementById(id).style.display="none";
    visible = false;
   }
 }

这篇关于如何让这个jQuery文本消失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆