Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 按钮以显示隐藏的html代码?_Java_Html_Web_Button - Fatal编程技术网

Java 按钮以显示隐藏的html代码?

Java 按钮以显示隐藏的html代码?,java,html,web,button,Java,Html,Web,Button,我想知道,用户一旦点击html/jsp网站上的某个按钮,是否可能在同一页面上出现某些内容?所以本质上一些文本是隐藏的,直到按钮被点击,然后它就会出现?我是web开发新手,因此我不确定这是否可行,谢谢使用JavaScript切换元素的显示样式属性: constdisplay=()=>document.querySelector('#elt').style.display='block'; const hide=()=>document.querySelector('#elt').style.di

我想知道,用户一旦点击html/jsp网站上的某个按钮,是否可能在同一页面上出现某些内容?所以本质上一些文本是隐藏的,直到按钮被点击,然后它就会出现?我是web开发新手,因此我不确定这是否可行,谢谢使用JavaScript切换元素的
显示
样式属性:

constdisplay=()=>document.querySelector('#elt').style.display='block';
const hide=()=>document.querySelector('#elt').style.display='none'
显示
隐藏

Hello world
您可以使用Jquery动态显示和隐藏页面上的元素。我建议您看看


下面是显示隐藏的html代码的
.hide()
.show()
函数按钮的一个小示例

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<body>
    <button id="showContent" >
Click Me to Show Content
</button>
<button id="hideContent" style="display:none" >
Click Me to Hide Content
</button>
    <div id="hiddenId" style="display:none">Welcome Dear!</div>
</body>
<script >

$("#showContent").click(function(){
    $("#hideContent").show();
    $("#showContent").hide();

$("#hiddenId").show();
});
$("#hideContent").click(function(){
    $("#showContent").show();
    $("#hideContent").hide();
$('#hiddenId').hide();
});
</script>
</html>

单击我以显示内容
单击“我”隐藏内容
欢迎亲爱的!
$(“#显示内容”)。单击(函数(){
$(“#hideContent”).show();
$(“#showContent”).hide();
$(“#hiddenId”).show();
});
$(“#hideContent”)。单击(函数(){
$(“#showContent”).show();
$(“#hideContent”).hide();
$('#hiddenId').hide();
});

查看jquery隐藏和显示功能确保这是可能的。要么重新加载页面(即向服务器发送一些信息,并根据需要重新加载页面),要么通过JavaScript更改DOM。这两种方法都有很多教程,这是基本要求。看看CSS和显示属性。你可以在任何JS框架中设置,也可以手动设置。在我看来,仅仅为了显示/隐藏而使用整个jQuery是一种过分的做法。退房;)杰普,完全是。可能是一个纯粹的js,就像在尼诺的awnser中看到的那样,但我只是喜欢jquery哈哈,但你是对的