jQuery插件:处理事件 [英] jQuery Plugin: Handling Events
问题描述
所以而不是这样:
$('#element_id')。mouseover(function(){
$这个).plugin();
});
$('#element_id')。mouseout(function(){
$(this).pluginHide();
});
我想尝试这样做:
$('#element_id')。plugin(????,????)
将这些引用替换为应该触发它的元素和事件的某种引用显示或隐藏我仍然用jQuery让我的脚湿润,所以如果一个解决方案是很明显的话,我可以忍受。
之后尝试一下,看起来我正在寻找内置的bind()功能。解决我原来的问题:
jQuery.fn.plugin = function(show,hide){
this.bind (show,function(){
//做某些事情显示
};
this.bind(hide,function(){
//做某事隐藏
};
};
I'm currently working on a jQuery plugin and I'm wondering if it would be possible to have the plugin listen for events rather than being triggered by events.
So instead of this:
$('#element_id').mouseover(function() {
$(this).plugin();
});
$('#element_id').mouseout(function() {
$(this).pluginHide();
});
I want to try to do something like this:
$('#element_id').plugin(????, ????);
And replace the ?'s with some sort of reference to the element and event that should trigger it to show or hide. I'm still getting my feet wet with jQuery, so bear with me if a solution to this is painfully obvious.
After experimenting a bit, it looks like I was looking for the built-in "bind()" function. To solve my original problem:
jQuery.fn.plugin = function(show, hide) {
this.bind(show, function() {
// Do something to show.
};
this.bind(hide, function() {
// Do something to hide.
};
};
这篇关于jQuery插件:处理事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!