2017-06-10 8 views
0

私はPHPファイルに取り組んでいます。私は削除を処理し、アップロードされたファイルを表示するajax jquery関数を作成しました。ときに、私はファイルを削除したいfirefoxで動作していないevent.preventdefault()関数が、クロムブラウザで正常に動作します。どのように私はこれを解決することができます。eventpreventdefault()がfirefoxで動作していませんか?

/* Read Upload Files */ 
function readuploadfiles(jrsid){ 
    var jourid = jrsid; 
    //console.log("Journal Id: "+jourid); 
    //var evt = e || window.event; 
    //evt.preventDefault(); 
    $.get("readuploadfiles.php", {jid: jourid}, function (data) { 
     //alert("Data: " + data + "\nStatus: " + status); 
     console.log(data); 
     $('#uploadfiles').html(data); 

    }); 
    return false; 
} 
/* Delete upload file */ 
function deleteuploadfiles(id){ 
    var conf = confirm("Are you sure, do you really want to delete file?"); 
    if (conf == true) {  
    event.preventDefault(); 
     $.post("deleteuploadfile.php", {id: id}, function (data) { 
       console.log(data); 
       readuploadfiles(data);    
      } 
     ); 
     return false; 
    } 

} 
+1

「イベント」はどこから来ていますか? – ModerateJavaScriptDev

+0

私は理解できませんでした。 – muraliniceguy97

答えて

4

イベントを渡す必要があります。

function deleteuploadfiles(id, **event**){ 

とも:

$("your button").click(function(**event**) { 
    deleteuploadfiles(id, event) 
1

あなたはイベントがトリガされたとき、あなたのメソッドに渡されるイベントオブジェクトへのアクセス権を持っている場合preventDefault方法でのみアクセス可能です。つまり、event.preventDefault()を動作させるには、まずメソッド内でeventオブジェクトを受け入れる必要があります。次のようなものが必要です:

function deleteuploadfiles(event, id){ 
    // Now you can use the event object 
    event.preventDefault(); 
} 

関連する問題