javascript - js中的多个输入...?
问题描述
它有效 - 当输入 #key1 为空时,我无法单击按钮。但我需要使用两个输入 - #key1 和 #key2。待办事项 - 当两者都为空或 1/2 时,没有人不能点击按钮。谢谢!!
<script type='text/javascript' src='http://code.jquery.com/jquery.min.js'></script>
<script type='text/javascript'>
$(function() {
$('#key1').keyup(function() {
if ($(this).val() == '') {
//Check to see if there is any text entered
// If there is no text within the input ten disable the button
$('.enableOnInput').prop('disabled', true);
} else {
//If there is text in the input, then enable the button
$('.enableOnInput').prop('disabled', false);
}
});
});
</script>
解决方案
尝试这个
$(function() {
$("#key1, #key2").keyup(function() {
if ($("#key1").val() == "" || $("#key2").val() == "") {
$(".enableOnInput").prop("disabled", true);
} else {
$(".enableOnInput").prop("disabled", false);
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="key1">
<input type="text" id="key2">
<button class="enableOnInput" disabled>Click me</button>
推荐阅读
- php - Laravel 8 中子域的签名 URL
- bash - 如何仅列出使用带有绝对(完整)路径的“ls”或不使用“ls”实现它的子目录?
- python - 如何使用电报机器人获取作者的用户名?
- javascript - 使用循环访问另一个 var 中的 var
- python - 在 Scapy Python 中访问数据包时出错
- grails - 如何将 Grails 从 Grails 2.4.4 升级到 Grails 4.0.1?
- oauth-2.0 - 在 Outlook 加载项中存储访问令牌的正确位置在哪里?
- python - 无法在 Jyputer 笔记本中读取 csv 文件
- java - 如何使用 FasterXML Jackson 将 XML 本身反序列化为列表
- java - Every time a player leaves my minecraft server, events are run twice. Why is this happening?