我创建了一个jQuery插件,现在我想其绑定到DOM这是由PHP脚本创建的元素。jQuery插件 - 动态绑定到元素
使用下面的标记为例:
<div class="showcase_window">
<div id='mywhatever'></div>
<div id='mywhatever2'></div>
<div id='mywhatever3'></div>
</div>
这工作:
$(document).ready(function(){
$('#mywhatever').showcase();
$('#mywhatever2').showcase();
$('#mywhatever3').showcase();
});
但由于标记是由PHP脚本创建的,我试图得到这样的工作:
$(document).ready(function(){
$('.showcase_window').children().on('showcase');
});
但我有点困惑......我明白'on'用于附加事件,但我我不知道如何去了解它...
非常感谢!
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。')儿童()上。({ 点击:函数(){ this.showcase();} }); – sree