jQuery禁用多个下拉菜单不起作用

jQuery禁用多个下拉菜单不起作用

本文介绍了jQuery禁用多个下拉菜单不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个企业进入他们的时间的下拉菜单。每天有一个下拉列表,标题为hours_dayname_open和hours_dayname_closed。我也有一个复选框将其标记为关闭。

I have dropdowns for a business to enter their hours. Each day has a drop down with the ID of hours_dayname_open and hours_dayname_closed. I also have a checkbox to mark it as closed. I am using the following jQuery to disable the drop down if it is checked:

$("#closed_monday").click( function(){
    if($(this).is(':checked')){
        $("#hours_monday_open").attr("disabled", true);
        $("#hours_monday_closed").attr("disabled", true);
    }else{
        $("#hours_monday_open").attr("disabled", false);
        $("#hours_monday_closed").attr("disabled", false);
    }
});

但是,如果选中复选框,则仅禁用/启用营业时间...关闭下拉菜单似乎被忽略了。

However, when the checkbox is selected only the open hours is disabled/enabled... The closed dropdown seems to be getting ignored.

推荐答案

奇怪的是,正确的属性是 disabled ,而不是 true

The proper attribute, strangely, is disabled, not true.

$("#hours_monday_open").attr("disabled", "disabled");

要启用它,请移除disabled属性:

To enable it, remove the disabled attribute:

$("#hours_monday_open").removeAttribute("disabled");

由于jQuery 1.6,您可以使用功能来清除/设置它。

Since jQuery 1.6, you can use the .prop() functionality to clear/set this.

这篇关于jQuery禁用多个下拉菜单不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 14:16