当我查看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选择器作为关键词,但没有运气。任何人都可以解释它并解释它的作用吗?
感谢。
又摸
答案 0 :(得分:1)
以下是http://api.jquery.com/jQuery/
的文档var foo = $('<div>',
{
class : "FooBar"
});
实际上是创建一个jquery对象并设置在大括号之间定义的props(在本例中为class)。你可以用foo.attr(“class”)返回它。
在你的情况下,文本prop被设置,它等于对象的内部html(用.text()返回)。
还修复了你的小提琴(由于文档中的大写D,从未调用onload :) http://jsfiddle.net/HUc2L/26/
答案 1 :(得分:0)
在jqfundamentals.com/试试这个,他们有更好的解释