layui table 行點擊事件與列點擊事件衝突

問題描述:工具

工具欄的點擊事件,會冒泡到行點擊事件中,原打算阻止事件冒泡 ,結果失敗,阻止不了,索性不用layui官網的工具欄tool和行row監聽事件。ui

table:this

<table id="conManager" lay-filter="conManager" class="layui-table layui-form"></table>

 

本來的監聽事件,以下:spa

        //監聽行單擊事件
        table.on('row(conManager)', function(obj){
          window.location.href = basePath + '/contract/look.do?conId='+obj.data.id;
        });
          //監聽行內工具欄操做
          table.on('tool(conManager)', function(obj){
              switch(obj.event) {
                  case 'edit':
                      break;
                  case 'del':break;
           default:
              }
          });

 

更改後,以下:code

#conTableInfo爲table容器的id
          //監聽行單擊事件
          $('#conTableInfo').on('click','div[lay-id="conManager"] .layui-table-body tr',function () {
              var _id = table.cache.conManager[parseInt($(this).attr('data-index'))].id;     
              window.location.href = basePath + '/contract/look.do?conId='+_id;
          })
          //監聽行內工具欄操做
          $('#conTableInfo').on('click','td[data-field="operation"]',function (e) {
              var _event = $(this).find('[lay-event]').attr('lay-event');
              var _obj = table.cache.conManager[parseInt($(this).parent('tr').attr('data-index'))];   //行內數據
              switch(_event) {
                  case 'edit':
               break;
                  case 'del':
                      break;
                  default:
              }
              return false; //阻止事件冒泡
          })
相關文章
相關標籤/搜索