Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.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_Live - Fatal编程技术网

Javascript jquery对象没有活动的方法

Javascript jquery对象没有活动的方法,javascript,jquery,live,Javascript,Jquery,Live,您好,我在jquery中有一个覆盖,我只使用版本1.6,但我想添加最新的库1.9.1,我有一个错误,uncaughttypeerror:Object[Object Object]在我的代码的第20行没有“live”方法,我的代码是这样的 (function($) { $('a[data-reveal-id]').live('click', function(e) { e.preventDefault(); var modalLocation = $(th

您好,我在jquery中有一个覆盖,我只使用版本1.6,但我想添加最新的库1.9.1,我有一个错误,uncaughttypeerror:Object[Object Object]在我的代码的第20行没有“live”方法,我的代码是这样的

(function($) {

    $('a[data-reveal-id]').live('click', function(e) {
        e.preventDefault();
        var modalLocation = $(this).attr('data-reveal-id');
        $('#'+modalLocation).reveal($(this).data());
    });


    $.fn.reveal = function(options) {


        var defaults = {  
            animation: 'fadeAndPop', //fade, fadeAndPop, none
            animationspeed: 300, //how fast animtions are
            closeonbackgroundclick: true, //if you click background will modal close?
            dismissmodalclass: 'close-reveal-modal' //the class of a button or element that will close an open modal
        }; 

        var options = $.extend({}, defaults, options); 

        return this.each(function() {

            var modal = $(this),
                topMeasure  = parseInt(modal.css('top')),
                topOffset = modal.height() + topMeasure,
                locked = false,
                modalBG = $('.reveal-modal-bg');


            if(modalBG.length == 0) {
                modalBG = $('<div class="reveal-modal-bg" />').insertAfter(modal);
            }           


            modal.bind('reveal:open', function () {
              modalBG.unbind('click.modalEvent');
                $('.' + options.dismissmodalclass).unbind('click.modalEvent');
                if(!locked) {
                    lockModal();
                    if(options.animation == "fadeAndPop") {
                        modal.css({'top': $(document).scrollTop()-topOffset, 'opacity' : 0, 'visibility' : 'visible'});
                        modalBG.fadeIn(options.animationspeed/2);
                        modal.delay(options.animationspeed/2).animate({
                            "top": $(document).scrollTop()+topMeasure + 'px',
                            "opacity" : 1
                        }, options.animationspeed,unlockModal());                   
                    }
                    if(options.animation == "fade") {
                        modal.css({'opacity' : 0, 'visibility' : 'visible', 'top': $(document).scrollTop()+topMeasure});
                        modalBG.fadeIn(options.animationspeed/2);
                        modal.delay(options.animationspeed/2).animate({
                            "opacity" : 1
                        }, options.animationspeed,unlockModal());                   
                    } 
                    if(options.animation == "none") {
                        modal.css({'visibility' : 'visible', 'top':$(document).scrollTop()+topMeasure});
                        modalBG.css({"display":"block"});   
                        unlockModal()               
                    }
                }
                modal.unbind('reveal:open');
            });     


            modal.bind('reveal:close', function () {
              if(!locked) {
                    lockModal();
                    if(options.animation == "fadeAndPop") {
                        modalBG.delay(options.animationspeed).fadeOut(options.animationspeed);
                        modal.animate({
                            "top":  $(document).scrollTop()-topOffset + 'px',
                            "opacity" : 0
                        }, options.animationspeed/2, function() {
                            modal.css({'top':topMeasure, 'opacity' : 1, 'visibility' : 'hidden'});
                            unlockModal();
                        });                 
                    }   
                    if(options.animation == "fade") {
                        modalBG.delay(options.animationspeed).fadeOut(options.animationspeed);
                        modal.animate({
                            "opacity" : 0
                        }, options.animationspeed, function() {
                            modal.css({'opacity' : 1, 'visibility' : 'hidden', 'top' : topMeasure});
                            unlockModal();
                        });                 
                    }   
                    if(options.animation == "none") {
                        modal.css({'visibility' : 'hidden', 'top' : topMeasure});
                        modalBG.css({'display' : 'none'});  
                    }       
                }
                modal.unbind('reveal:close');
            });     


        modal.trigger('reveal:open')

            //Close Modal Listeners
            var closeButton = $('.' + options.dismissmodalclass).bind('click.modalEvent', function () {
              modal.trigger('reveal:close')
            });

            if(options.closeonbackgroundclick) {
                modalBG.css({"cursor":"pointer"})
                modalBG.bind('click.modalEvent', function () {
                  modal.trigger('reveal:close')
                });
            }
            $('body').keyup(function(e) {
                if(e.which===27){ modal.trigger('reveal:close'); } // 27 is the keycode for the Escape key
            });



            function unlockModal() { 
                locked = false;
            }
            function lockModal() {
                locked = true;
            }   

        });
    }
})(jQuery);
(函数($){
$('a[数据显示id')。live('click',函数(e){
e、 预防默认值();
var modalLocation=$(this.attr('data-discover-id');
$('#'+modalLocation).discover($(this.data());
});
$.fn.reveal=功能(选项){
变量默认值={
动画:“fadeAndPop”,//fade,fadeAndPop,无
动画速度:300,//动画有多快
closeonbackgroundclick:true,//如果单击background将关闭吗?
dismissmodalclass:“close-reveal-modal”//将关闭打开模式的按钮或元素的类
}; 
var options=$.extend({},默认值,选项);
返回此值。每个(函数(){
var modal=$(此),
topMeasure=parseInt(modal.css('top')),
topOffset=模态高度()+topMeasure,
锁定=错误,
modalBG=$('.discover modal bg');
if(modalBG.length==0){
modalBG=$('')。插入后面(模态);
}           
modal.bind('leaver:open',function(){
modalBG.unbind('click.modalEvent');
$('..+options.dismissmodalclass).unbind('click.modalEvent');
如果(!已锁定){
锁模态();
如果(options.animation==“fadeAndPop”){
css({'top':$(document.scrollTop()-topOffset,'opacity':0,'visibility':'visible'});
modalBG.fadeIn(options.animationspeed/2);
modal.delay(options.animationspeed/2).设置动画({
“top”:$(document.scrollTop()+topMeasure+'px',
“不透明度”:1
},options.animationspeed,unlockModal());
}
如果(options.animation==“淡入淡出”){
css({'opacity':0,'visibility':'visible','top':$(document.scrollTop()+topmease});
modalBG.fadeIn(options.animationspeed/2);
modal.delay(options.animationspeed/2).设置动画({
“不透明度”:1
},options.animationspeed,unlockModal());
} 
如果(options.animation==“无”){
css({'visibility':'visible','top':$(document.scrollTop()+topMeasure});
css({“display”:“block”});
解锁模式()
}
}
模态。解除绑定(“显示:打开”);
});     
modal.bind('leaver:close',函数(){
如果(!已锁定){
锁模态();
如果(options.animation==“fadeAndPop”){
modalBG.delay(options.animationspeed)、fadeOut(options.animationspeed);
模态动画({
“top”:$(document.scrollTop()-topOffset+'px',
“不透明度”:0
},options.animationspeed/2,function(){
css({'top':topmease,'opacity':1,'visibility':'hidden'});
解锁模式();
});                 
}   
如果(options.animation==“淡入淡出”){
modalBG.delay(options.animationspeed)、fadeOut(options.animationspeed);
模态动画({
“不透明度”:0
},options.animationspeed,function(){
css({'opacity':1,'visibility':'hidden','top':topmease});
解锁模式();
});                 
}   
如果(options.animation==“无”){
css({'visibility':'hidden','top':topmease});
css({'display':'none'});
}       
}
模态。解除绑定(“显示:关闭”);
});     
modal.trigger('显示:打开')
//关闭模态侦听器
var closeButton=$('.'+options.dismissmodalclass).bind('click.modalEvent',函数(){
modal.trigger('显示:关闭')
});
如果(选项。关闭背景单击){
css({“游标”:“指针”})
modalBG.bind('click.modalEvent',函数(){
modal.trigger('显示:关闭')
});
}
$('body').keyup(函数(e){
if(e.which==27){modal.trigger('leaver:close');}//27是转义键的键码
});
函数unlockModal(){
锁定=错误;
}
函数lockmodel(){
锁定=真;
}   
});
}
})(jQuery);
从v1.9开始。有几个版本(从v1.7开始)都不推荐使用它

以下是文档中关于重写它以使用
委托
on
(我在每次调用上面添加了注释)的内容:

根据继承方法重写
.live()
方法很简单;以下是所有三种事件附件方法的等效调用模板:

因此,在您的情况下,而不是:

$('a[data-reveal-id]').live('click', function(e) { // ...
你会想要的

$(document).delegate('a[data-reveal-id]', 'click', function(e) { // ...
// Or
$(document).on('click', 'a[data-reveal-id]', function(e) { // ...
但是,您通常可以找到一个容器元素,该元素更靠近要钩住的元素,如果是这样,您希望使用该元素,而不是
文档
。例如,假设所有的$(document).delegate('a[data-reveal-id]', 'click', function(e) { // ... // Or $(document).on('click', 'a[data-reveal-id]', function(e) { // ...
$(document).on('click', 'a[data-reveal-id]', function(e) { // ...
$('#stuff').on('click', 'a[data-reveal-id]', function(e) { // ...
$( document ).on( 'click', 'a[data-reveal-id]', function(e) { ... });