2016-12-19 15 views
0

我有一個表的數據,一個標題行和一個頁腳行。 我需要捕捉點擊,並在表格上的每個單元格上的更多事件,除了頁腳,在頁腳行,我有一個表單提交和一些鏈接,現在我無法導航的鏈接,任何建議。捕獲表onclick時窗體和鏈接的問題

var botonPulsado = false; 
$(document).ready(function() 
{ 
    $("#valTable td").mousedown(function(event) { 
     botonPulsado = true; 
     if(event.ctrlKey){   
      if ($(this).attr('class') == 'flag') { 
       seleccionados.push($("[type='hidden']", this).attr('id')); 
       $(this).prev('td').toggleClass("seleccionado", true); 
      } else if ($(this).attr('class') == 'valor'){ 
       seleccionados.push($("[type='hidden']", $(this).next('td')).attr('id')); 
       $(this).toggleClass("seleccionado", true); 
      } else if($(this).attr('class') == 'fecha') { 
       $(this).parent().find('td').each(function (i){ 
        if ($(this).attr('class') == 'flag') { 
         seleccionados.push($("[type='hidden']", this).attr('id')); 
         $(this).prev('td').toggleClass("seleccionado", true); 
        } else if ($(this).attr('class') == 'valor'){ 
         seleccionados.push($("[type='hidden']", $(this).next('td')).attr('id')); 
         $(this).toggleClass("seleccionado", true); 
        } 
       }); 
      } 
     } else { 
      if ($(this).attr('class') != undefined){ 
       $('.seleccionado').each(function(i) { $(this).toggleClass("seleccionado", false); }); 
       seleccionados = []; 
      } else { 
       event.stopPropagation(); 
      } 
     } 
     return false; 
    }).mouseover(function (event) { 
     if (botonPulsado){ 
      if(event.ctrlKey){  
       if ($(this).attr('class') == 'flag') { 
        seleccionados.push($("[type='hidden']", this).attr('id')); 
        $(this).prev('td').toggleClass("seleccionado", true); 
       } else if ($(this).attr('class') == 'valor'){ 
        seleccionados.push($("[type='hidden']", $(this).next('td')).attr('id')); 
        $(this).toggleClass("seleccionado", true); 
       } 
      } 
     } 
    }).bind("selectstart", function() { 
     return false; 
    }) 
    $(document).mouseup(function(){ 
     botonPulsado = false; 
    }); 
    $("#valTable").on("click", "th", function(event) { 
     if(event.ctrlKey){ 
      indice = ($(this).index()*2) -1; 
      $("#valTable tr").each(function(){ 
       var celda = $(this).find("td:eq(" + indice + ")"); 
       if (celda.attr('class') == 'valor'){ 
        celda.toggleClass("seleccionado", true); 
        seleccionados.push($("[type='hidden']", $(this).find("td:eq(" + (indice + 1) + ")")).attr('id')); 
       } 

      }); 
     } else { 
      $('.seleccionado').each(function(i) { $(this).toggleClass("seleccionado", false); }); 
      seleccionados = [];  
     } 
    }); 
    $("#valTable").on("click", "tfoot tr td",function(event){ 
     alert('footer'); 
     event.preventDefault(); 
     event.stopPropagation(); 
     return true; 
    }); 
}); 

這是我的jQuery代碼,我得到了警告味精「頁腳」,但鏈接或表單提交不運行。

非常感謝。

回答

0

我得到了它,

如果我加入這行

window.location.href = $(this).find("a").attr("href"); 

在每個

event.stopPropagation(); 

鏈接的下一行,並提交表單運行。