当我研究 http://docs.jquery.com/Plugins/Authoring 时,我无法理解语法。
我实际上在JsFiddle上设置了一个类似的脚本:http://jsfiddle.net/huyoumo/HUc2L/24/
下面是代码片段:
var methods = {
init : function( options ) {
return this.each(function(){
var $this = $(this),
data = $this.data('tooltip'),
tooltip = $('<div />', {
text : $this.attr('title')
});
// If the plugin hasn't been initialized yet
if ( ! data ) {
/*
Do more setup stuff here
*/
$(this).data('tooltip', {
target : $this,
tooltip : tooltip
});
}
});
},
更具体地说:
tooltip = $('<div />', {
text : $this.attr('title')
});
我调试了代码,发现工具提示是一个JQuery对象(似乎),它只有一个子对象(一个HTMLDivElement)。
我试图谷歌JQuery选择器作为关键词,但没有运气。谁能阐明并解释它的作用?
谢谢。
优莫
该 http://api.jquery.com/jQuery/的文档
var foo = $('<div>',
{
class : "FooBar"
});
实际上是创建一个jquery对象,并设置在大括号之间定义的props(在本例中为类)。你可以用foo.attr("class")返回它。
在您的情况下,设置了文本属性,这等于对象的内部 html(使用 .text() 返回)。
还修复了你的小提琴(由于文档 :) 中的大写 D 而从未调用过 onload。http://jsfiddle.net/HUc2L/26/
在他们有更好的解释 jqfundamentals.com/试试这个