【问题标题】:Problems with form and links when capturing table onclick捕获表格 onclick 时的表单和链接问题
【发布时间】:2017-05-04 14:57:02
【问题描述】:

我有一个包含数据的表格,一个标题行和一个页脚行。 我需要在表格上除页脚之外的每个单元格上捕捉点击和更多事件,在页脚行中,我有一个表单提交和一些链接,现在我无法使用链接导航,任何建议。

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 代码,我收到警报消息“页脚”,但链接或表单提交不运行。

非常感谢。

【问题讨论】:

    标签: jquery forms html-table


    【解决方案1】:

    我明白了,

    如果我添加这一行

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

    在每一行的下一行

    event.stopPropagation();
    

    链接和表单提交运行。

    【讨论】:

      猜你喜欢
      • 2014-03-26
      • 2016-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-23
      相关资源
      最近更新 更多