Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.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 如何使用angularjs中的自定义指令使用Unform jQuery插件设置浏览器默认复选框的样式_Javascript_Jquery_Angularjs_Angularjs Directive_Jquery Uniform - Fatal编程技术网

Javascript 如何使用angularjs中的自定义指令使用Unform jQuery插件设置浏览器默认复选框的样式

Javascript 如何使用angularjs中的自定义指令使用Unform jQuery插件设置浏览器默认复选框的样式,javascript,jquery,angularjs,angularjs-directive,jquery-uniform,Javascript,Jquery,Angularjs,Angularjs Directive,Jquery Uniform,我只是想设计一个复选框,我将jquery插件和angularjs一起使用 下面是我想为插件设置样式的复选框输入元素: <label><input type="checkbox" plugin-uniform id="inline">&nbsp;Inline editing</label> 下面是Layout.initUnform()代码: var Layout = function() { //other stuff

我只是想设计一个复选框,我将jquery插件和angularjs一起使用

下面是我想为插件设置样式的复选框输入元素:

<label><input type="checkbox" plugin-uniform id="inline">&nbsp;Inline editing</label>
下面是Layout.initUnform()代码:

    var Layout = function() {

    //other stuff

            initUniform: function (els) {
                if (els) {
                    jQuery(els).each(function () {
                            if ($(this).parents(".checker").size() == 0) {
                                $(this).show();
                                $(this).uniform();
                            }
                        });
                } else {
                    handleUniform();
                }
            }

    function handleUniform() {
        if (!jQuery().uniform) {
            return;
        }
        var test = $("input[type=checkbox]:not(.toggle), input[type=radio]:not(.toggle, .star)");
        if (test.size() > 0) {
            test.each(function () {
                    if ($(this).parents(".checker").size() == 0) {
                        $(this).show();
                        $(this).uniform();
                    }
                });
        }
    }

    //other stuff

    }
我已经准备好了
uniform.default.css
jquery.uniform.js


有人能告诉我如何使用自定义指令将浏览器默认复选框样式设置为angularjs中的jQuery插件复选框样式吗?

调用
Layout.initUniform()
时缺少
els
参数

由于在页面中的angular library之前包含jQuery库时,指令的link函数已经将元素作为jQuery对象公开,因此实际上不需要布局函数

您的
handlenform
函数有几个缺陷

要检查plugun是否存在,应执行
if($.fn.pluginName)
。 此外,如果有许多元素与该指令绑定在一起,那么每次该指令运行时,都会循环遍历所有元素

试试这个:

myApp.directive('pluginUniform', function() {
    return {
        restrict: 'A',
        link: function(scope, element, attrs) {
           /* element is jQuery object*/
           if (!element.parents(".checker").length) { /* size() is deprecated */
                 element.show().uniform();                          
           }
        }
    };
});

是的,现在可以工作了,谢谢:)。但是它现在在控制台上给了我这个错误
TypeError:undefined不是
的函数。您在页面中的前面包括jQuery了吗?这是使
angular.element
使用jQueryYes所必需的,它在angularjs lib之前。通常的原因是路径错误或忘记包含文件
myApp.directive('pluginUniform', function() {
    return {
        restrict: 'A',
        link: function(scope, element, attrs) {
           /* element is jQuery object*/
           if (!element.parents(".checker").length) { /* size() is deprecated */
                 element.show().uniform();                          
           }
        }
    };
});