Javascript 将jquery选项与$.fn一起使用会导致错误

Javascript 将jquery选项与$.fn一起使用会导致错误,javascript,jquery,html,css,Javascript,Jquery,Html,Css,在插件(jquery)的一部分中,我将CSS规则添加到元素中。代码如下: tagSet.eq(index).css({ options.tag_direction : (xy[0]+"px "+strictCSS), "position" : ("relative"+" "+strictCSS), "top" : (xy[1]+"px "+strictCSS),

在插件(jquery)的一部分中,我将CSS规则添加到元素中。代码如下:

tagSet.eq(index).css({
                    options.tag_direction : (xy[0]+"px "+strictCSS),
                    "position" : ("relative"+" "+strictCSS),

                    "top" : (xy[1]+"px "+strictCSS),
                })
但是,如果我用options替换“left”,那么它就会出错。以下是错误:

SyntaxError: missing : after property id


options.tag_direction_hor : (xy[0]+"px "+strictCSS),
我这样做是因为我希望用户(开发人员)能够使用带有“左”或“右”css规则的插件,以避免对源代码进行黑客攻击

我还有一个
console.log(options.get\u direction\u hor)
,输出正确。我在这里遗漏了javascript对象吗

以下是选项签名:

$.fn.mtTagger = function(options){
        var options = $.extend({
            tag_class : ".mtTagElement", //
            tag_before_callback : null,  // a callback to gets fired when the pages(or section) loads       
            tag_htmlTag : "span", // HTML elements to be selected as children           
            tag_limit_to_class : false, // if true, then the selection is $(element.class) than it was $(element) if false
            tag_mouse_in_callback : null, // a callback to gets fired when the mouse moves enters
            tag_mouse_out_callback : null, // a callback to gets fired when the mouse moves leaves
            tag_strict_css : false, // if true, then !important will be appened to the end of each CSS rule
            tag_direction_hor : null
        }, options)

您的语法不正确。对象文字定义不能像您试图提供的那样包含动态键。标记方向。相反,您可以将其分为两部分:

var styles = {
    position: "relative" + " " + strictCSS,
    top: xy[1] + "px " + strictCSS
};
styles[options.tag_direction] = xy[0] + "px " + strictCSS;
tagSet.eq(index).css(styles);

还记得清理最后一个对象属性后的尾随逗号(将在旧IE中中断)。

该代码可能会进行wierdly解析,我看到
“top”:})成为一种可能性。。。try而不是null-尝试使用未定义或0或“”或其他替代null的内容。。