jqueryプラグインを作成しましたが、これをPHPスクリプトで作成されたDOM要素にバインドします。Jqueryプラグイン - 要素に動的にバインドします
$(document).ready(function(){
$('#mywhatever').showcase();
$('#mywhatever2').showcase();
$('#mywhatever3').showcase();
});
をしかし、マークアップは、PHPスクリプトによって作成されているので、私は仕事にこのような何かを取得しようとしています:
<div class="showcase_window">
<div id='mywhatever'></div>
<div id='mywhatever2'></div>
<div id='mywhatever3'></div>
</div>
これは動作します。例として、次のマークアップを使用して
:
しかし、私は少し混乱しています...私はイベントを添付するために使用されていることを理解していますが、どのようにそれについて行くか分からない...
多くのありがとう!
P.S:ここでは、プラグインです:
$.fn.showcase = function() {
return this.each(function() {
var $this = $(this);
$this.find(".sc_itm_display").hover(function() {
$this.find(".sc_img_front").stop(true,true).fadeOut("slow");
}, function() {
$this.find(".sc_img_front").stop(true,true).fadeIn("slow");
});
$this.find('.sc_color_select img').click(function() {
var color_path_1 = $(this).attr("src").replace("color","1");
var color_path_2 = $(this).attr("src").replace("color","2");
$this.find('.sc_itm_display .sc_img_back img').attr("src",color_path_1);
$this.find('.sc_itm_display .sc_img_front img').attr("src",color_path_2);
});
});
};
「on」はイベントのみです。プラグインを添付するものではありません。 – gdoron
$ {'showcase_window'}。children()。({ click:function(){ this.showcase(); } }); – sree