Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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 jQuery插件|为什么不';这部分不行吗?_Javascript_Jquery - Fatal编程技术网

Javascript jQuery插件|为什么不';这部分不行吗?

Javascript jQuery插件|为什么不';这部分不行吗?,javascript,jquery,Javascript,Jquery,我有下面的代码,有点太长了,忽略选项,没有它也应该可以工作,但似乎有些地方我做错了,因为什么都没有发生 var container = 'body'; var structureWrapper = '<div class="content-login"></div>'; var structure = [ '<form name="', opts.formClass, '" class="', opts.formClass, '" method="post

我有下面的代码,有点太长了,忽略
选项
,没有它也应该可以工作,但似乎有些地方我做错了,因为什么都没有发生

 var container = 'body';

 var structureWrapper = '<div class="content-login"></div>';

 var structure = [
'<form name="', opts.formClass, '" class="', opts.formClass, '" method="post" action="#">',
    '<fieldset class="', opts.fieldsWrapper, '">',
        '<fieldset class="', opts.userWrapper, '">',
            '<label for="', opts.userInt, '" class="', opts.userLbl, '"><img src="', opts.userIcon, '" alt="', opts.userName, '" /></label>',
            '<input type="text" name="', opts.userInt, '" class="', opts.userInt, '" placeholder="', checkNameLenght(opts.userName, namesLenght.userNameLenght, 16, 'Username'), '" value="" autocomplete="off" />',
        '</fieldset>',
        '<fieldset class="', opts.passWrapper, '">',
            '<label for="', opts.passInt, '" class="', opts.passLbl, '"><img src="', opts.passIcon, '" alt="', opts.passName, '" /></label>',
            '<input type="password" name="', opts.passInt, '" class="', opts.passInt, '" placeholder="', checkNameLenght(opts.passName, namesLenght.passNameLenght, 16, 'Password'), '" value="" autocomplete="off" />',
        '</fieldset>',
        '<fieldset class="', opts.btnWrapper, '">',
            '<button type="submit" name="', opts.btnInt, '" class="', opts.btnInt, '">', checkNameLenght(opts.btnName, namesLenght.btnNameLenght, 7, 'Login'), '</button>',
        '</fieldset>',
    '</fieldset>',
    '<div class="toogle-button">',
        '<ul class="inside">',
            '<li class="toogle"><a><img src="assets/gfx/toogle.png" alt="Back" /></a></li>',
        '</ul>',
    '</div>',
'</form>',
'<div class="toogle-buttons">',
'</div>'
];





var getProps = function(obj) {
return {
    'position': 'absolute',
    'top': (($(window).height() - $(obj).outerHeight()) / 2) + 'px',
    'left': (($(window).width() - $(obj).outerWidth()) / 2) + 'px'
}
}

var showObj = function(obj, callback) {
return setTimeout(function() {
    if (opts.centerObj === true) {
        var cssProps = getProps(obj);
        obj.css(cssProps).fadeIn('slow');
    }
    else {
        obj.fadeIn('slow');
    }
    if (typeof callback == 'function') {
        callback.call(this);
    }
}, 1500);
}


var appendStructure = function(wrapper, structure, cls) {

return $(wrapper).appendTo(container).hide(function() {
    var obj = $(container).find(cls);
    $(structure.join('')).appendTo(obj);
    showObj(obj, function() {
        if (opts.centerObj === true) {
            $(window).resize(function() {
                var cssProps = getProps(obj);
                obj.css(cssProps);
            });
        }
    });
});
}

appendStructure(structureWrapper, structure, '.content-login');
var容器='body';
var structureWrapper='';
变量结构=[
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',检查名称长度(opts.btnName,namelenght.btnNameLenght,7,'登录'),'',
'',
'',
'',
“
    ”,
  • 当没有设置opts属性时,您的代码会发生故障,因为您无法对无法首先转换为字符串的内容执行串联

    在你的代码中,“长度”一词拼错了“长度”

    除此之外,我已经阅读了代码表单JSFIDLE,并将其提到了一个可以工作的地方

    我对“checkNameLength”函数做了一个小改动,删除了“namesLength”参数,并将其实例替换为“name.length”

    var容器='body';
    变量选项={
    是的,
    formClass:“”,
    用户包装器:“”,
    userInt:“”,
    userLbl:“”,
    用户图标:“”,
    用户名:“”,
    密码:“”,
    Btname:“
    }
    /*已删除冗余名称长度var*/
    var checkNameLength=函数(名称、允许长度、默认名称){
    
    如果((name.lengthAside)与您的问题无关,请让我告诉您,您将“length”拼错为“lenght”.我知道,我之前提到过,但它不会影响代码,它是我定义的
    var
    。我们如何可以忽略
    opts
    ?您在使用它时没有为我们定义它,那么我们如何尝试调试它?如果您删除它们,您会得到相同的结果,它们与代码的这一部分应该做什么无关,它们是相关的R在我的插件中。正如你所看到的,它们要么用于在控制台中调试,要么用于表单中的类,要么用于表单中的标签或占位符,我认为这对你来说也不重要,它是不起作用的主要功能,应该做什么。这就是为什么我问的原因,因为即使我已经定义了所有的变量和函数ons仍然不起作用。它应该像独立代码一样工作。如果opts错误被删除,它就可以工作。检查它。这不是它应该如何工作的吗?谢谢。但这不是我遇到的问题。我知道lenght拼写错误,但我是故意这样做的,我以后可能会修改它。至于
    namesLength
    参数,它是出于某种原因,我有很多名字,我把所有的名字长度都放在了这个对象中,这就是为什么它看起来像这样。我在寻找一些语法错误,我可能会错过,因为无论我怎么尝试,在我的插件中它都不起作用,但我想我已经找到了线索。再次感谢:)不用担心。如果你不介意我说,我关心你的评论“至于‘名称长度’…”。首先,将长度存储在自变量中会破坏与字符串的关联,其次,我无法想象将长度与字符串分离在何处是可行的,这似乎是一个危险的游戏。你是对的,也许我会找到另一种方法来计算长度。这是我的观点,你已经有了le因此,没有理由将其存储在其他任何地方。如果出于任何原因需要在函数调用中使用它,则可以使用(例如)higherThanSix(stringVar.length)——函数返回val>6
    var container = 'body';
     var opts = {
        debug: true,
         formClass:"",
         userWrapper:"",
         userInt:"",
         userLbl:"",
         userIcon:"" ,
         userName:"",
         passName:"",
         btnName:""
     }
    
      /*Removed redundant namesLength var*/   
     var checkNameLength = function(name, allowedLength, defaultName) {
         if ((name.length<= allowedLength) && !(/\s[^a-z]/i.test(name))) {
             return name;
         }
         else {
             if (opts.debug === true) {
                 console.log(name + ' is to long or contains special characters / numbers | Please      choose a name shorter than ' + allowedLength+ ' characters or remove any character / number');
             }
             return defaultName;
         }
     }
    
    
     var structureWrapper = '<div class="content-login"></div>';
    
     var structure = [
         '<form name="', opts.formClass, '" class="', opts.formClass, '" method="post" action="#">',
        '<fieldset class="', opts.fieldsWrapper, '">',
            '<fieldset class="', opts.userWrapper, '">',
                '<label for="', opts.userInt, '" class="', opts.userLbl, '"><img src="', opts.userIcon, '" alt="', opts.userName, '" /></label>',
                '<input type="text" name="', opts.userInt, '" class="', opts.
    userInt, '" placeholder="', checkNameLength(opts.userName,  16, 'Username'), '" value="" autocomplete="off" />',
            '</fieldset>',
            '<fieldset class="', opts.passWrapper, '">',
                '<label for="', opts.passInt, '" class="', opts.passLbl, '"><img src="', opts.passIcon, '" alt="', opts.passName, '" /></label>',
                '<input type="password" name="', opts.passInt, '" class="', opts.passInt, '" placeholder="', checkNameLength(opts.passName, 16, 'Password'), '" value="" autocomplete="off" />',
            '</fieldset>',
            '<fieldset class="', opts.btnWrapper, '">',
                '<button type="submit" name="', opts.btnInt, '" class="', opts.btnInt, '">', checkNameLength(opts.btnName, 7, 'Login'), '</button>',
            '</fieldset>',
        '</fieldset>',
        '<div class="toogle-button">',
            '<ul class="inside">',
                '<li class="toogle"><a><img src="assets/gfx/toogle.png" alt="Back" /></a></li>',
            '</ul>',
        '</div>',
    '</form>',
    '<div class="toogle-buttons">',
    '</div>'
    ];
    
    
    
    
    
    var getProps = function(obj) {
        return {
            'position': 'absolute',
            'top': (($(window).height() - $(obj).outerHeight()) / 2) + 'px',
            'left': (($(window).width() - $(obj).outerWidth()) / 2) + 'px'
         }
     }
    
     var showObj = function(obj, callback) {
         return setTimeout(function() {
             if (opts.centerObj === true) {
                 var cssProps = getProps(obj);
                 obj.css(cssProps).fadeIn('slow');
             }
             else {
                 obj.fadeIn('slow');
            }
             if (typeof callback == 'function') {
                callback.call(this);
             }
         }, 1500);
     }
    
    
     var appendStructure = function(wrapper, structure, cls) {
    
         return $(wrapper).appendTo(container).hide(function() {
             var obj = $(container).find(cls);
             $(structure.join('')).appendTo(obj);
             showObj(obj, function() {
                 if (opts.centerObj === true) {
                     $(window).resize(function() {
                         var cssProps = getProps(obj);
                         obj.css(cssProps);
                     });
                 }
             });
         });
     }
    
     appendStructure(structureWrapper, structure, '.content-login');