操作样式显示属性
Manipulate the Style Display property
<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {
width: 500px;
height: 500px;
background-color: lightblue;
}
</style>
</head>
<body>
<p>Click the "Try it" button to set the display property of the DIV element to "none":</p>
<button onclick="myFunction()">Try it</button>
<div id="myDIV">
This is my DIV element.
</div>
<p><b>Note:</b> The element will not take up any space when the display property set to "none".</p>
<script>
function myFunction() {
document.getElementById("myDIV").style.display = "none";
}
</script>
</body>
</html>
我正在使用样式显示属性。我如何操作代码,以便在开始时隐藏DIV元素,当我单击按钮时,它会出现?
修改Javascript函数:
function myFunction() {
document.getElementById("myDIV").style.display = "block";
}
CSS: 和
#myDIV {
width: 500px;
height: 500px;
background-color: lightblue;
display: none;
}
所以基本上#myDIV
一开始不会显示。点击按钮后,myFunction()
运行,#myDIV
显示为block, div
默认显示为block。
您可以在div上初始设置一个display:none
。和javascript代码,你应该工作,除了改变none为block
必须为display: none;添加div的样式。
当按钮触发时,您需要更改显示。
document.getElementById("myDIV").style.display = "block";
试试下面的代码,如果可以的话
<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {
width: 500px;
height: 500px;
background-color: lightblue;
display:none;
}
</style>
</head>
<body>
<p>Click the "Try it" button to set the display property of the DIV element to "none":</p>
<button onclick="myFunction()">Try it</button>
<div id="myDIV">
This is my DIV element.
</div>
<p><b>Note:</b> The element will not take up any space when the display property set to "none".</p>
<script>
function myFunction() {
document.getElementById("myDIV").style.display = "block";
}
</script>
</body>
</html>
相关文章:
- 带有填充属性的SVG矩形显示在包含元素的上方插入框阴影
- 重写CSS:使用jquery显示none属性
- 对象的属性显示为未定义
- 离子模态未打开(类型错误:无法读取未定义的属性“显示”)
- HTML “标题”属性显示单词“未定义” - 例如.“主页未定义”
- 使剑道 UI 下拉列表将“选择控件”的“标题”属性显示为剑道工具提示
- 内容显示中的 JavaScript 错误“无法设置未定义的属性”显示”
- 动态添加的控件属性显示为 controls=“ ” 而不是控件
- 为什么获胜't我的json对象的`email`属性显示在我的jade模板中
- Angular:如何根据项目的属性显示icon.png
- 如何使用属性显示带有CSS3转换的隐藏元素
- 文本和输入元素以相同的方式追加和给定属性.显示文本,但不显示输入.为什么
- 基于属性显示html
- 修改title属性显示的工具提示
- 使用标签选择图像文件,但有属性显示输入
- 使用使用rel属性显示的模式编辑gridview单元格
- 按数据属性显示列表中的前三项
- 使用数据弹出属性显示 Jquery-ui 对话框
- 使用数据弹出属性显示 UI 对话框
- 检测属性显示从无显示到显示块