javascript - 单击禁用按钮时,如何使模式出现?
问题描述
Bellow 是 JS 代码,它使按钮被禁用,直到所有输入都被填充。我需要在禁用时显示模式。
$(document).ready(function() {
validate_dependent();
$('#txtDependentName, #txtDependentRelation, #txtDependentBirthDate').change(validate_dependent);
});
function validate_dependent() {
if ($('#txtDependentName').val().length > 0 && $('#txtDependentRelation').val().length > 0 && $('#txtDependentBirthDate').val().length > 0) {
$("[name=next_dependent]").prop("disabled", false);
} else {
$("[name=next_dependent]").prop("disabled", true);
}
}
<button type="button" name="next_dependent" class="btn btn-success form-control" style="width:10%; float:right;" onclick="openTab(event, 'educationTab')">Next</button>
我怎样才能做到这一点。欣赏你的回答。谢谢你。
解决方案
您可以在禁用按钮周围放置一个 div 并将一个单击事件附加到该 div。例子:
$(document).ready(function() {
//validate_dependent();
//$('#txtDependentName, #txtDependentRelation, #txtDependentBirthDate').change(validate_dependent);
$('.disabled-button-wrapper').click(function() {
console.log('click event works');
// add your logic here
});
});
function validate_dependent() {
if ($('#txtDependentName').val().length > 0 && $('#txtDependentRelation').val().length > 0 && $('#txtDependentBirthDate').val().length > 0) {
$("[name=next_dependent]").prop("disabled", false);
} else {
$("[name=next_dependent]").prop("disabled", true);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="disabled-button-wrapper"><button type="button" name="next_dependent" class="btn btn-success form-control" style="width:10%; float:right;">Next</button></div>
推荐阅读
- javascript - 如何使用javascript在excel中添加数据验证列表
- http - URL 中的美元符号、尖括号和双引号是什么意思?
- excel - 在一个 wpf 项目中,我正在使用 Microsoft.Office.Interop.Excel 导入 excel 文件。我是否需要部署 Office 主互操作程序集?
- mongodb - 更新嵌入式文档 Mongo 字段名称
- scala - 与 jSerialComm 的串行通信不发送任何内容
- javascript - 仅在特定位置之间且仅在有空格时才在字符串内添加换行符-Javascript
- python - 类似于matlab的for循环
- java - 如何在列表项目java中使用多个类
- javascript - this.setState 不是文件上传 ReactJS 的函数
- google-apps-script - 为什么 setValue() 只粘贴第一个单元格而不是整个范围?