2017-06-21 264 views
1

我想下載一個onclick事件的excel文件。它允許我用chrome下載excel文件,但不能用於Firefox。不知道是什麼問題。我正在低於錯誤。下載的excel文件不適用於Firefox,但適用於Chrome

ReferenceError: event is not defined 

下面是我的javascript功能

function hyperlinkFn(){ 
var htmlTbl=""; 
var htmlTbl1=""; 
var string = event.target.parentElement.name; 
var tempString=[]; 
var temp= new Array(); 
for(var i=0;i<string.length;i++){ 
    if(string[i]=="|"){ 
     temp.push(tempString); 
     tempString=[]; 
    }else{ 
     tempString+=string[i]; 
    } 
} 

userStoryModalRelease = temp[0]; 
userStoryModalPID = temp[1]; 
userStoryModalPrjName = encodeURIComponent(temp[2]); 
userStoryModalTeam = encodeURIComponent(temp[3]); 
userStoryAltId=encodeURIComponent(temp[4]); 
userStoryModalStatus = temp[5]; 
userStoryModalTeam = userStoryModalTeam.replace(", ", ","); 

var uri="getUserStoryDetails.htm?release=" + userStoryModalRelease + "&projectId=" + userStoryModalPID + "&projectName=" + userStoryModalPrjName + 
    "&team=" + userStoryModalTeam + "&alternateId=" + userStoryAltId + "&view=" + storyView; 
var encode = encodeURI(uri); 
window.location = encode; 

}我在哪裏DataTable中

 { 
           title : "Total Points", 
           data : function(data, type, row, meta) { 
            return data.totalSum+'<a name="'+ data.releaseNum +'|'+ data.projectId +'|'+ data.projectName +'|'+ data.team + '|'+ data.altId + '|total|'+'" onclick="hyperlinkFn()">'  
              + '<i class="fa fa-file-excel-o font-size-15 " title="Click here to export details " aria-hidden="true"></i></a>'; 
           }, 
           className : "center storypoint yellow_fill pos-rel" 
          } ], 
+0

沒有與'無功串= event.target.parentElement.name的問題;'在哪裏事件定義? – Aaron

回答

1

調用此函數更改click結合像下面讓

HTML代碼活動將發揮作用:

$(document).on('click', '.classname', function(event){ 
    var htmlTbl=""; 
    var htmlTbl1=""; 
    var string = event.target.parentElement.name; 
    var tempString=[]; 
    var temp= new Array(); 
    for(var i=0;i<string.length;i++){ 
     if(string[i]=="|"){ 
      temp.push(tempString); 
      tempString=[]; 
     }else{ 
      tempString+=string[i]; 
     } 
    } 

    userStoryModalRelease = temp[0]; 
    userStoryModalPID = temp[1]; 
    userStoryModalPrjName = encodeURIComponent(temp[2]); 
    userStoryModalTeam = encodeURIComponent(temp[3]); 
    userStoryAltId=encodeURIComponent(temp[4]); 
    userStoryModalStatus = temp[5]; 
    userStoryModalTeam = userStoryModalTeam.replace(", ", ","); 

    var uri="getUserStoryDetails.htm?release=" + userStoryModalRelease + "&projectId=" + userStoryModalPID + "&projectName=" + userStoryModalPrjName + 
     "&team=" + userStoryModalTeam + "&alternateId=" + userStoryAltId + "&view=" + storyView; 
    var encode = encodeURI(uri); 
    window.location = encode; 
}) 

注:從超鏈接刪除onclick事件和超鏈接添加class,代之以.classname

+0

Thanks..this爲我工作 – MSV

0

那類名貌似這已經在這裏涵蓋: ReferenceError: event is not defined error in Firefox

的WebKit如下IE的使用全局符號作爲「事件」的舊行爲,但Firefox不支持。當您使用jQuery時,該庫會標準化 行爲並確保您的事件處理程序通過事件 參數。

function hyperlinkFn(){需求,成爲function hyperlinkFn(event){

相關問題