私はjqueryプラグインの連鎖性に取り組んでいますが、以下のjqueryで正常に動作しclick
ます。
$(document).ready(function(){
$('.call-parent').parent_child({
target: '.element'
});
$('.call-child-1').click(function(){
$(this).parent_child().child_1();
return false;
});
$('.call-child-2').click(function(){
$(this).parent_child().child_2();
return false;
});
});
(function($) {
$.fn.extend({
parent_child: function(options) {
var defaults = {
target:''
}
var options = $.extend(defaults, options);
var o = options;
var $this = this;
var $cm = this.click(function(ei) {
alert('parent');
$this.child_1();
return false;
});
$this.child_1 = function() {
alert('child 1');
};
$this.child_2 = function() {
alert('child 2');
};
return $cm;
}
})
})(jQuery);
each
しかし、プラグインを使用したりready
、プラグインを使用したりすると、エラーが発生します。
$(document).ready(function(){
$('.call-parent').parent_child({
target: '.element'
});
$('.call-child-1').click(function(){
$(this).parent_child().child_1();
return false;
});
$('.call-child-2').click(function(){
$(this).parent_child().child_2();
return false;
});
});
(function($) {
$.fn.extend({
parent_child: function(options) {
var defaults = {
target:''
}
var options = $.extend(defaults, options);
var o = options;
var $this = this;
var $cm = this.each(function(ei) {
alert('parent');
$this.child_1();
return false;
});
$this.child_1 = function() {
alert('child 1');
};
$this.child_2 = function() {
alert('child 2');
};
return $cm;
}
})
})(jQuery);
エラーメッセージ、
$this.child_1は関数ではありません[BreakOnThis Error]
なぜ私はまたはでそれを行うことができないのですeach
かready
?それとも私はそれを間違ってしましたか?