我正在看http://docs.jquery.com/Plugins/Authoring#Defaults_and_Options为jQuery创建一个简单的插件。在有关选项和设置的部分之后,我做了以下操作,但没有用(脚本遇到设置后退出)。
var settings = {
'location' : 'top',
'background-color': 'blue'
}
...
$this.css('backgroundColor', settings.background-color); // fails here
一旦我从背景色中删除了破折号,一切就可以正常工作了。
var settings = {
'location' : 'top',
'backgroundColor': 'blue' // dash removed here
}
...
$this.css('backgroundColor', settings.backgroundColor);
我是否缺少某些内容,或者jQuery文档是否出错?
没有。解析器会将其解释为减法运算符。
你可以做settings['background-color']
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句