Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery原型继承_Jquery_Prototype - Fatal编程技术网

jQuery原型继承

jQuery原型继承,jquery,prototype,Jquery,Prototype,为了更好地理解jQuery原型对象jQuery.fn,我编写了一些代码,但我不明白为什么它不起作用: jQuery.fn.appender = function(text) { // i want every jQuery-Element to inherit a method called appender (I know that there is already "append" - this is just for learning). this.each(funct

为了更好地理解jQuery原型对象
jQuery.fn
,我编写了一些代码,但我不明白为什么它不起作用:

jQuery.fn.appender = function(text) {  
    // i want every jQuery-Element to inherit a method called appender (I know that there is already "append" - this is just for learning).
    this.each(function(index, element) {
        $(this).append(text);
    })
};

$("diveins").appender(); // nothing is happening

这个问题与继承无关。这是因为您没有为函数提供
text
参数
diveins
也是无效的选择器。大概应该是
.diveins
。最后请注意,您的
each()
循环是多余的,因为默认情况下jQuery将对集合中的每个元素应用
append()
方法。试试这个:

$.fn.appender=函数(文本){
$(此).append(文本);
};
$(“.diveins”).appender('foo');//注意此处添加的参数

这个问题与继承无关。这是因为您没有为函数提供
text
参数
diveins
也是无效的选择器。大概应该是
.diveins
。最后请注意,您的
each()
循环是多余的,因为默认情况下jQuery将对集合中的每个元素应用
append()
方法。试试这个:

$.fn.appender=函数(文本){
$(此).append(文本);
};
$(“.diveins”).appender('foo');//注意此处添加的参数