我有一个文本框#Email,我有两个下拉列表菜单,#Carrier和#Phones。当输入电子邮件时,我想只启用Carriers下拉框而不启用电话。选择运营商后,必须启用电话下拉列表。只有在选择了电子邮件和运营商时,才能启用电话下拉列表。如果用户输入电子邮件并从#carriers和#phones中选择项目,然后删除电子邮件,则必须禁用两个下拉菜单。有没有办法可以复句?输入电子邮件时,以下是工作承运人。
$(document).ready(function () { //Will check for e-mail and enable #Phones dropdownlist, otherwise, it will disable dropdownlist of #Phones
$('#Email').on('input change', function () { //check to see if email textbox is empty
if ($(this).val() == '') {
$('#Phones').prop('disabled', true);
}
else {
$('#Phones').prop('disabled', false);
}
});
});
需要这包括#Phones&&载波数目
<script>
$(document).ready(function () {//need this to enable when email and carriers is selected.
$('#Email').on('input change', function () { //check to see if email is empty
if ($(this).val() == '') {
$('#Phones').prop('disabled', true);
}
else {
$('#Phones').prop('disabled', false);
}
});
});
答案 0 :(得分:1)
$('#Email').on('input change', function () { //check to see if email is empty
if ($(this).val() == '') {
$('#Carriers').prop('disabled', true);
$('#Phones').prop('disabled', true);
}
else {
$('#Carriers').prop('disabled', false);
}
});
这将在您更改电子邮件时启用运营商,但如果您将其删除,则会禁用运营商和电话。
$('#Carriers').change(function () {
if ($('#Carriers').val() == '') {
$('#Phones').prop('disabled', true);
}
else {
$('#Phones').prop('disabled', false);
}
});
这将在您更换运营商时启用电话。您已经在第一次操作时检查电子邮件,如果没有值,则禁用运营商,因此您不需要在此处再次执行此操作。