Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 选择父元素未禁用的输入元素_Javascript_Jquery_Twitter Bootstrap_Checkbox - Fatal编程技术网

Javascript 选择父元素未禁用的输入元素

Javascript 选择父元素未禁用的输入元素,javascript,jquery,twitter-bootstrap,checkbox,Javascript,Jquery,Twitter Bootstrap,Checkbox,小崽子,我已经盯着/用谷歌搜索了一个小时,所以我想是时候向苏寻求帮助了 基本上,我有一个对输入复选框进行操作的插件,每个复选框都嵌套在相应的标签中。选中复选框应该会使某些事情发生,但前提是父标签未被禁用。在我的代码中,它对所有复选框执行操作,而不管它们是否应该被禁用 HTML: 将您的JS更改为: var pluginDiv = this; // Defined in my plugin, works fine var pluginCheckboxButtons = pluginDiv

小崽子,我已经盯着/用谷歌搜索了一个小时,所以我想是时候向苏寻求帮助了

基本上,我有一个对输入复选框进行操作的插件,每个复选框都嵌套在相应的标签中。选中复选框应该会使某些事情发生,但前提是父标签未被禁用。在我的代码中,它对所有复选框执行操作,而不管它们是否应该被禁用

HTML:


将您的JS更改为:

var pluginDiv = this;   // Defined in my plugin, works fine
var pluginCheckboxButtons = pluginDiv
    .find('input:checkbox') // use :checkbox shorthand
        .filter(function(){
            return ! $(this).parent().is(':disabled');
        });

由于disabled不是label的默认属性,请尝试更改

return !($(this).parent().prop("disabled"));


我不认为元素有一个disabled属性,当然不是一个有效的disabled属性!没有意识到标签不应该具有默认属性。让它们成为按钮而不是标签会更有意义吗?不会,除非您将复选框移到更改的父元素之外,因为交互元素不能有交互子元素。在HTML5中,您可以使用以data-开头的属性向任何DOM元素添加数据。一种方法是。或者,您可以将一个禁用的类添加到标签中,然后说.is.disabled。@问题是,我仍然需要添加disabled属性,以便引导应用正确的样式:-/添加额外的类/属性会使其不那么优雅。我一直在查找,找不到引导支持禁用属性的地方在标签中。我可能忽略了这一点,但他们似乎使用了类。是否确实添加禁用的类和删除禁用的属性不会同时设置其样式?
var pluginDiv = this;   // Defined in my plugin, works fine
var pluginCheckboxButtons = pluginDiv
    .find('input:checkbox') // use :checkbox shorthand
        .filter(function(){
            return ! $(this).parent().is(':disabled');
        });
return !($(this).parent().prop("disabled"));
return !$(this).parent().is("[disabled]")