我喜欢jQuery插件架构,但是,当我想要保留对插件实例的引用以便稍后在我的代码中访问属性或方法时,我发现它令人沮丧(可能是由于我对我缺乏了解).
编辑:我想澄清我真正想要做的是保留对插件中使用的方法和属性的引用,以便我以后可以使用它们
让我们以AJAX加载图标为例.在更传统的OOP环境中,我可以这样做:
var myIcon = new AJAXIcon();
myIcon.start();
//some stuff
myIcon.stop();
Run Code Online (Sandbox Code Playgroud)
我的对象的方法和属性存储在变量中供以后使用.现在,如果我想在jQuery插件中具有相同的功能,我会从我的主代码中调用它,有点像这样:
$("#myId").ajaxIcon()
Run Code Online (Sandbox Code Playgroud)
按照惯例,我的插件需要返回传递给我的插件的原始jQuery对象,允许可链接性,但如果我这样做,我就失去了访问插件实例的方法和属性的能力.
现在,我知道你可以在我的插件中声明一个公共函数,有点像
$.fn.ajaxIcon = function(options) {
return this.each(function () {
//do some stuff
}
}
$.fn.ajaxIcon.stop = function() {
//stop stuff
}
Run Code Online (Sandbox Code Playgroud)
但是,在不违反返回原始jQuery对象的约定的情况下,我无法保留对我想要引用的插件的特定实例的引用.
我希望能够做到这样的事情:
var myIcon = $("myId").ajaxIcon(); //myIcon = a reference to the ajaxIcon
myIcon.start();
//some stuff
myIcon.stop();
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
仅在Firefox中,如果我尝试给svg路径一个模式引用,如:
path {fill:url(#ref); }
在外部样式表中,它呈现不可见.如果我内联,或在页面上的标签中,它可以工作.
这是我的小提琴,这是我的代码转储,因为SO不会让我发布只是小提琴. http://jsfiddle.net/v5VDp/1/
<pattern id="texture_base" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<image x="0" y="0" width="213" height="122" xlink:href=""/>
</pattern>
<pattern id="texture1" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<rect fill='url(#color1)' stroke="none" x="0" y="0" width="213" height="122"/>
<rect fill='url(#texture_base)' x="0" y="0" width="213" height="122"/ />
</pattern>
</defs>
</svg>
Run Code Online (Sandbox Code Playgroud)
.slice:nth-child(6n + 2)路径{fill:url(#textite1); }
https://dl.dropbox.com/s/wkzaoiwnw6ghsmd/simple_svg_test.css
好吧,也许我正在做一些非常愚蠢的事情.
我在OSX 10.6.1上.
我想在我的路径中添加mysql,所以我将以下内容添加到我的.bashrc中
PATH = ${PATH}:/usr/local/mysql/bin
export PATH
Run Code Online (Sandbox Code Playgroud)
在运行终端时,它不起作用,我希望,因为.bash_profile目前没有加载.bashrc.
但如果我手动输入bash,我会收到以下错误
bash: PATH: command not found
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?