Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.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
Javascript 在创建对象后附加jquery事件_Javascript_Jquery_Popup_Bpopup - Fatal编程技术网

Javascript 在创建对象后附加jquery事件

Javascript 在创建对象后附加jquery事件,javascript,jquery,popup,bpopup,Javascript,Jquery,Popup,Bpopup,我正在使用bPopup jquery库。。要添加到onclose事件的语法非常简单: $('element_to_pop_up').bPopup({ onOpen: function() { alert('onOpen fired'); }, onClose: function() { alert('onClose fired'); } }) 我要做的是在创建对象后向onClose事件添加一些内容。。有可能吗?通常,您可以通过创建一个稍后处理的函数来实现这一点: var

我正在使用bPopup jquery库。。要添加到onclose事件的语法非常简单:

$('element_to_pop_up').bPopup({
     onOpen: function() { alert('onOpen fired'); }, 
     onClose: function() { alert('onClose fired'); }
})

我要做的是在创建对象后向onClose事件添加一些内容。。有可能吗?

通常,您可以通过创建一个稍后处理的函数来实现这一点:

var myOnClose = function() { alert('onClosed fired'); }
function doOnClose() { myOnClose(); }

$('element_to_pop_up').bPopup({
    onOpen: function() { alert('onOpen fired'); }, 
    onClose: doOnClose
})

// later...
myOnClose = function() { console.log("Doing something different!"); }

一般来说,您可以通过创建一个稍后处理的函数来实现这一点:

var myOnClose = function() { alert('onClosed fired'); }
function doOnClose() { myOnClose(); }

$('element_to_pop_up').bPopup({
    onOpen: function() { alert('onOpen fired'); }, 
    onClose: doOnClose
})

// later...
myOnClose = function() { console.log("Doing something different!"); }

一般来说,您可以通过创建一个稍后处理的函数来实现这一点:

var myOnClose = function() { alert('onClosed fired'); }
function doOnClose() { myOnClose(); }

$('element_to_pop_up').bPopup({
    onOpen: function() { alert('onOpen fired'); }, 
    onClose: doOnClose
})

// later...
myOnClose = function() { console.log("Doing something different!"); }

一般来说,您可以通过创建一个稍后处理的函数来实现这一点:

var myOnClose = function() { alert('onClosed fired'); }
function doOnClose() { myOnClose(); }

$('element_to_pop_up').bPopup({
    onOpen: function() { alert('onOpen fired'); }, 
    onClose: doOnClose
})

// later...
myOnClose = function() { console.log("Doing something different!"); }

您可以访问
bPopup
对象,该对象将出现在元素的
数据中

$('element_to_pop_up').bPopup({
    onOpen: function() { alert('onOpen fired'); }, 
    onClose: function() { alert('onClose fired'); }
});

$('element_to_pop_up').data('bPopup');

注意:不能保证创建的对象始终存在于元素的数据中。但这是一种广泛使用的方法。最好依赖提供的回调。

您可以访问
bPopup
对象,该对象将出现在元素的
数据中

$('element_to_pop_up').bPopup({
    onOpen: function() { alert('onOpen fired'); }, 
    onClose: function() { alert('onClose fired'); }
});

$('element_to_pop_up').data('bPopup');
var realOnclose = f1;
function myOnClose(){realOnclose();}
 $('element_to_pop_up').bPopup({ 
    onOpen: function() { alert('onOpen fired'); },
    onClose: myOnClose
})

function f1() { alert('onClose fired'); } 
function f2() { alert('hey I am another function'); } 

//when you want to change the action when onclose...
realOnclose = f2;

注意:不能保证创建的对象始终存在于元素的数据中。但这是一种广泛使用的方法。最好依赖提供的回调。

您可以访问
bPopup
对象,该对象将出现在元素的
数据中

$('element_to_pop_up').bPopup({
    onOpen: function() { alert('onOpen fired'); }, 
    onClose: function() { alert('onClose fired'); }
});

$('element_to_pop_up').data('bPopup');
var realOnclose = f1;
function myOnClose(){realOnclose();}
 $('element_to_pop_up').bPopup({ 
    onOpen: function() { alert('onOpen fired'); },
    onClose: myOnClose
})

function f1() { alert('onClose fired'); } 
function f2() { alert('hey I am another function'); } 

//when you want to change the action when onclose...
realOnclose = f2;

注意:不能保证创建的对象始终存在于元素的数据中。但这是一种广泛使用的方法。最好依赖提供的回调。

您可以访问
bPopup
对象,该对象将出现在元素的
数据中

$('element_to_pop_up').bPopup({
    onOpen: function() { alert('onOpen fired'); }, 
    onClose: function() { alert('onClose fired'); }
});

$('element_to_pop_up').data('bPopup');
var realOnclose = f1;
function myOnClose(){realOnclose();}
 $('element_to_pop_up').bPopup({ 
    onOpen: function() { alert('onOpen fired'); },
    onClose: myOnClose
})

function f1() { alert('onClose fired'); } 
function f2() { alert('hey I am another function'); } 

//when you want to change the action when onclose...
realOnclose = f2;

注意:不能保证创建的对象始终存在于元素的数据中。但这是一种广泛使用的方法。最好依赖提供的回调。

如果要添加而不是替换最初提供给
onClose
选项的代码,可以触发自定义事件:

var realOnclose = f1;
function myOnClose(){realOnclose();}
 $('element_to_pop_up').bPopup({ 
    onOpen: function() { alert('onOpen fired'); },
    onClose: myOnClose
})

function f1() { alert('onClose fired'); } 
function f2() { alert('hey I am another function'); } 

//when you want to change the action when onclose...
realOnclose = f2;
$('element_to_pop_up').bPopup({
    onClose: function() {
        // Do the original stuff here.
        this.trigger('popup:close');
    }
});
$('element_to_pop_up').on('popup:close', function() {
    // Do the additional stuff here.
});
然后,您可以在以后的任何时间注册自定义事件的处理程序:

$('element_to_pop_up').bPopup({
    onClose: function() {
        // Do the original stuff here.
        this.trigger('popup:close');
    }
});
$('element_to_pop_up').on('popup:close', function() {
    // Do the additional stuff here.
});

注意:查看bPopup库的代码,它看起来像
onClose
函数的上下文是原始jQuery对象,但如果不是,则替换为:
$('element\u to\u pop\u')。trigger('popup:close')

如果要添加而不是替换最初提供给
onClose
选项的代码,可以触发自定义事件:

$('element_to_pop_up').bPopup({
    onClose: function() {
        // Do the original stuff here.
        this.trigger('popup:close');
    }
});
$('element_to_pop_up').on('popup:close', function() {
    // Do the additional stuff here.
});
然后,您可以在以后的任何时间注册自定义事件的处理程序:

$('element_to_pop_up').bPopup({
    onClose: function() {
        // Do the original stuff here.
        this.trigger('popup:close');
    }
});
$('element_to_pop_up').on('popup:close', function() {
    // Do the additional stuff here.
});

注意:查看bPopup库的代码,它看起来像
onClose
函数的上下文是原始jQuery对象,但如果不是,则替换为:
$('element\u to\u pop\u')。trigger('popup:close')

如果要添加而不是替换最初提供给
onClose
选项的代码,可以触发自定义事件:

$('element_to_pop_up').bPopup({
    onClose: function() {
        // Do the original stuff here.
        this.trigger('popup:close');
    }
});
$('element_to_pop_up').on('popup:close', function() {
    // Do the additional stuff here.
});
然后,您可以在以后的任何时间注册自定义事件的处理程序:

$('element_to_pop_up').bPopup({
    onClose: function() {
        // Do the original stuff here.
        this.trigger('popup:close');
    }
});
$('element_to_pop_up').on('popup:close', function() {
    // Do the additional stuff here.
});

注意:查看bPopup库的代码,它看起来像
onClose
函数的上下文是原始jQuery对象,但如果不是,则替换为:
$('element\u to\u pop\u')。trigger('popup:close')

如果要添加而不是替换最初提供给
onClose
选项的代码,可以触发自定义事件:

$('element_to_pop_up').bPopup({
    onClose: function() {
        // Do the original stuff here.
        this.trigger('popup:close');
    }
});
$('element_to_pop_up').on('popup:close', function() {
    // Do the additional stuff here.
});
然后,您可以在以后的任何时间注册自定义事件的处理程序:

$('element_to_pop_up').bPopup({
    onClose: function() {
        // Do the original stuff here.
        this.trigger('popup:close');
    }
});
$('element_to_pop_up').on('popup:close', function() {
    // Do the additional stuff here.
});

注意:查看bPopup库的代码,它看起来像
onClose
函数的上下文是原始jQuery对象,但如果不是,则替换为:
$('element\u to\u pop\u')。trigger('popup:close')

除非插件有以后添加内容的方法,否则不可能,在创建实例时传入对象。除非插件有以后添加内容的方法,否则不可能,在创建实例时传入对象。除非插件有以后添加内容的方法,否则不可能,对象是在创建实例时传入的。除非插件有以后添加东西的方法,否则不可能在创建实例时传入对象。我喜欢这种方法。。为什么不能保证对象在数据上?不存在它总是应该存在的地方吗?@RaphaelCabrera是的,对象应该存在于数据中。同样,这取决于插件开发人员。如果开发人员没有将对象持久化到元素的数据中,那么您就无法访问它。由于这是jQuery插件中广泛使用的方法,所以您可以信赖它。。为什么不能保证对象在数据上?不存在它总是应该存在的地方吗?@RaphaelCabrera是的,对象应该存在于数据中。同样,这取决于插件开发人员。如果开发人员没有将对象持久化到元素的数据中,那么您就无法访问它。由于这是jQuery插件中广泛使用的方法,所以您可以信赖它。。为什么不能保证对象在数据上?不存在它总是应该存在的地方吗?@RaphaelCabrera是的,对象应该存在于数据中。同样,这取决于插件开发人员。如果开发人员没有将对象持久化到元素的数据中,那么您就无法访问它。由于这是jQuery插件中广泛使用的方法,所以您可以信赖它。。为什么不能保证对象在数据上?不存在它总是应该存在的地方吗?@RaphaelCabrera是的,对象应该存在于数据中。同样,这取决于插件开发人员。如果开发人员没有将对象持久化到元素的数据中,那么您就无法访问它。因为这是jQuery插件中广泛使用的方法,所以您可以依赖它。