javascript - 当我在 javascript 上使用标签时,为什么不能通过 css 设置标签样式?
问题描述
我也在尝试使用 css 设置我的 div 和按钮的样式。但是在为我的按钮包含一个 javascript 代码之后,它的功能是显示和隐藏我的 div 表单。无论我在我的 css 上输入什么,似乎都不再影响我的 div 的样式。
我需要做什么?
这是我的代码:
var theForm = document.getElementById('show-form').style.visibility = 'hidden';
var theButton = document.getElementById('show-button');
var thexButton = document.getElementById('hide-button');
thexButton.onclick = function() {
document.getElementById('show-form').style.visibility = 'hidden';
}
theButton.onclick = function() {
document.getElementById('show-form').style.visibility = 'visible';
}
.hide-button {
background: red;
}
.form-wrapper {
margin: auto;
width: 50%;
}
<button id="show-button">Add Report</button>
<div class="form-wrapper" id="show-form">
<button id="hide-button">X</button>
<form action="add.php" method="post">
<label>File Name: </label> <input class="input2" type="text" required><br>
<input class="submit-btn" type="submit" name="insert" value="Save">
</form>
</div>
解决方案
由于您的按钮具有 hide-button 的 id 但在 css 中您将其选择为 .hide-button 所以更改以下代码
.hide-button {
background: red;
}
对此
#hide-button {
background: red;
}
推荐阅读
- angular - Jasmine Karma - 未捕获的错误:macroTask 'setInterval':无法转换到 'running',期待状态 'scheduled',是 'notScheduled'
- tsql - 如何从这个全名中解析出名字、姓氏和中间名
- sql - 复合年增长率返回 发生无效浮点运算
- jquery - 以json格式传递带有ajax的html是正确的做法吗?
- php - 转换PHP多维数组,使值成为键,其他值成为每个键的数组
- angularjs - AngularJs 模态按钮确定和取消不起作用
- sas - 如何将 SAS 数据集作为宏中的参数传递?
- python - 如何遍历张量的所有元素并获取索引
- php - PHP For循环迭代应该调整
- sql - redshift 中的 CONVERT_TIMEZONE 产生与预期相反的结果