javascript - 使用 Javascript 阻止元素发送到下一行
问题描述
我有一个在开头隐藏的按钮元素。
但是,我必须使用 JavaScript 在某些触发器上显示它。但是当它被触发时,它会被推到下一行。见下图:-
我真正想要的是:-
这是我的 HTML 代码:-
<div id="toolbar">
<a href="#" class="btn btn-secondary">Launch Access Log Report</a> <a href="#" style="display: none" class="btn btn-secondary" type="button" id="fresh" >Refresh Table Updated</a>
</div>
以及将其推送到下一行的我的 JavaScript 代码:-
function check(data)
{
if (data === 'no')
{ document.getElementById("fresh").style.display='block';}
}
是什么搞砸了,请解释一下,我该如何解决这个问题。
解决方案
display: block
将从新行开始,并占据可用的全部宽度。使用display: inline-block
或display: inline
代替。
使用display: block
<button onclick="show()">Show</button>
<div>
<a href="#">Launch Access Log Report</a>
<a href="#" style="display: none; background-color: red;" id="fresh">Refresh Table Updated</a>
</div>
<script>
function show() {
document.getElementById("fresh").style.display = "block";
}
</script>
使用display: inline-block
<button onclick="show()">Show</button>
<div>
<a href="#">Launch Access Log Report</a>
<a href="#" style="display: none; background-color: red;" id="fresh">Refresh Table Updated</a>
</div>
<script>
function show() {
document.getElementById("fresh").style.display = "inline-block";
}
</script>
推荐阅读
- javascript - 如何删除点前的空格?
- python - 如何通过与名称匹配的键将字典值分配给数据框
- laravel - Moloquent laravel hasOne & hasMany 不能在 ObjectId 中使用 foreignKey
- django - 如何在 Django 中过滤两个模型(一对一)
- ios - 当从同一目标下的目标 c 文件访问时,在 Swift 文件中设置的用户默认值返回 nil
- python - 使用 matplotlib 的毫米波动画
- c# - 在计算 Vector3.Distance 时是否应考虑帧速率依赖性?
- uber-api - 优步访问菜单获取 API 的问题
- java - 普通对象变量还是 JavaFX 对象属性?
- c++ - 在 C++ 类中初始化 C 数组