簡體   English   中英

調用e.preventDefault()時,javascript錯誤“e”未定義

[英]javascript error “e” undefined when calling e.preventDefault()

我沒有編寫這段代碼,而且我無法弄清楚為什么我在第一個e.preventDefault()得到以下錯誤。 我已經嘗試在.click事件處理程序中移動該代碼,將其傳遞給function(e){} ,將其替換為return false ,聲明var e = $(this.href) (不要笑,我'我試圖學習),我檢查了a href返回的值,它返回正確的hash 視頻播放,但是當我運行IE調試器時,我收到此錯誤。 有人請告訴我如何正確調試和修復此問題。 謝謝

在此輸入圖像描述

HTML

 <a href="#video1" class="blueBtn modal" style="width:150px;"><span>Watch Video <img width="10" height="17" src="images/bluebtn.png"></span></a></div>

使用Javascript

// FANCY BOX
$("a.modal").click(function(){
    var inline=$(this).attr('href');
    $.fancybox({
        'transitionIn'      : 'none',
        'transitionOut'     : 'none',
        'href'              : inline,
        'onComplete'        : function(){
            $(inline+' .flowPlayer').videoPlayer();
            $.fancybox.center(true);
        },
        'onClosed'          : function(){loc();}
    });
    e.preventDefault();         
});

$(".print").click(function(e){
    window.open("print-docs/"+$(this).parent().attr('id')+".html","print","width=1,height=1");
    e.preventDefault();
});

function loc(){
    var location=window.location.href;
    var replaceHash=location.replace(document.location.hash,"");
    window.location.assign(replaceHash);
}

應該

$("a.modal").click(function(e) { // Note the "e" parameter
    // etc
});

...相反,就像在第二次點擊處理程序中一樣。 請參閱,這兩個函數都是作為第一個參數提供的jQuery Event對象 (本機Event對象的包裝器)。 但您仍然必須讓JavaScript知道您的函數中將引用此參數的確切方式。

您需要自己添加e參數:

$("a.modal").click(function(e){  //<------- right there
    var inline=$(this).attr('href');
    $.fancybox({
        'transitionIn'      : 'none',
        'transitionOut'     : 'none',
        'href'              : inline,
        'onComplete'        : function(){
            $(inline+' .flowPlayer').videoPlayer();
            $.fancybox.center(true);
        },
        'onClosed'          : function(){loc();}
    });
    e.preventDefault();         
});

你錯過了e參數:

$("a.modal").click(function(e){

   e.preventDefault();  
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM