Button to display html code that is hidden?

问题: I am wondering if it is possible for once a user clicks on a button on a html/jsp website that something appears on the same page? So essentially some text is hidden until...

问题:

I am wondering if it is possible for once a user clicks on a button on a html/jsp website that something appears on the same page? So essentially some text is hidden until the button is click and then it will appear? I'm new to web dev so am unsure if this is even possible, thanks


回答1:

Use JavaScript to toggle the display style attribute of an element:

const display = () => document.querySelector('#elt').style.display = 'block';
const hide = () => document.querySelector('#elt').style.display = 'none';
<button onclick="display()">Display</button>
<button onclick="hide()">Hide</button>
<div id="elt">Hello world</div>


回答2:

You can use Jquery to dynamically show and hide elements on your page. I would recommend looking at it
https://jsfiddle.net/rxnfwzoj/1/
here is a small example of the .hide() and .show() function

  • 发表于 2019-02-23 00:52
  • 阅读 ( 201 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除