最佳答案
我在看 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);
Am I missing something, or are the jQuery docs wrong?