0

javascript と jquery を学習したばかりで、jquery データテーブルの使用に問題があります。

私のデータはphpに2回投稿されました。スクリプトに event.preventDefault を実装して false を返す方法がわかりません。

olistorderproduktdatatable = $("#listorderprodukttable").dataTable({
    "bJQueryUI": true, "bPaginate": false, "bFilter": true, "bInfo": false, "bAutoWidth": true, "sDom": 'Rlfrtip', 
    "bServerSide": true,
    "sSearch" :"Filter",
    "bDestroy": true,
    "sAjaxSource": "share/content/helper/datatablelistorderprodukt.php" 
});

$('#listorderprodukttable tbody').delegate("tr", "click", rowClickAddPosition);

function rowClickAddPosition(){
    //Welche Zeile wurde selektiert und ID herausfiltern 
   if (hlr)
      $("td:first", hlr).parent().children().each(function(){$(this).removeClass('markrow');});
   hlr = this;
   $("td:first", this).parent().children().each(function(){$(this).addClass('markrow');});

   // You can pull the values out of the row here if required
   var a = $("td:first", this).text();
   var b = $("td:eq(1)", this).text();

   selectedRow      = a;  //ID der Zeile WICHTIGE VARIABLE!!!

    //Abfrage ob ID leer ist, also ob es überhaupt Einträge gibt.
   if(selectedRow != "No matching records found"){
        $.ajax({
            type : 'POST',
            url : 'share/content/helper/orderaddposition.php',
            cache: false,
            data: {
                SelectedProdukt : selectedRow,
                BestellID       : BestellID
            },
            success: function(data) {
                callbackaddposition();
            }
        });
    }
}

イベントをキャッチする方法がわかりません。

4

2 に答える 2

0

event.stopPropagation ()を使用return falseし、次のような関数で使用します。

$('#listorderprodukttable tbody').delegate("tr", "click", function(e){
    rowClickAddPosition(e);
    return false;// to stop bubbling up
});

function rowClickAddPosition(e){
   e.stopPropagation();
   // remaining code
于 2013-10-16T10:56:03.903 に答える
0

試しましたか:

function rowClickAddPosition(e) {
   e.preventDefault();
   // ...
}
于 2013-10-16T10:54:12.943 に答える