javascript - BS4:用按钮禁用按钮
问题描述
我目前正在尝试为我正在开发@work 的项目自学BS4。基本上我所拥有的是一个按钮组(2 个。左侧是活动的,右侧是禁用的) 我想要做的是禁用左侧并激活右侧,反之亦然。这是代码:
<div class="btn-group">
<button type="button" id="showscore" class="btn btn-success">Show</button>
<button type="button" id="hidescore" class="btn btn-danger" disabled>Hide</button>
</div>
和 JS:
function lockbutton() {
var x = document.getElementById("#showscore").button;
if(x.click()) {
document.getElementById("hidescore").disabled = true;
} else{
document.getElementById("hidescore").disabled = false;
}
}
不要为 JS/jQuery 代码烤我。我已经知道错了。但我找不到解决方法。
解决方案
您可能希望使用 bootstrap 中包含的 jQuery 库。
$(document).ready(function() {
$('#showscore').click(function() {
$('#hidescore').prop('disabled', false);
$(this).prop('disabled', true);
});
$('#hidescore').click(function() {
$('#showscore').prop('disabled', false);
$(this).prop('disabled', true);
});
});
推荐阅读
- android - 使用动态页面创建 ViewPager(上一页/下一页查看器,循环,例如 Book 应用程序)
- java - Firebase 实时查询 startAt 和 endAt 无法在联合属性上按预期工作
- laravel - Pivot 在 Laravel Nova 自定义规则函数内部返回 null 但不在其外部
- javascript - 在 JavaScript 中将一个数组转换/转置为另一个数组?
- c# - 无法正确将 JSON 发送到 Unity 中的服务器
- r - 获取点网格上多元核密度估计的协方差矩阵
- android - 调用 stopForeground 时通知颜色发生变化
- ansible - 子文件夹中多个文件中的 Ansible 更改字符串
- javascript - 如何在不使用 setTimeout() 的情况下让我的快速应用回调函数在调用 res.send 之前等待?
- java - 伊拉克电话号码的java正则表达式