doushen2154 2018-11-06 11:22
浏览 430

用jQuery获取th的id

I have this table:

  <th id="a" width="250">Backlog</th>
  <th id="b" width="250">Wip</th>
  <th id="c" width="250">Testing</th> 
  <th id="d" width="250">DOD</th>
</tr>

My requirement enter image description here

I have 4 columns backlog, WIP, Testing, DOD. If I drag from Backlog to Testing I want to get drop columns id. Ie. i want to save it to database. I tried this:

jQuery(function() {
  jQuery(".draggable").draggable({
    containment: "#containment-wrapper",
    scroll: false,
    stop: function(event, ui) {
      // Show dropped position.
      var id = $(this).attr('id');
      var trid = $(this).closest('tr').attr('id');
      alert(trid);
      var Stoppos = $(this).position();
      model = {
        id: id,
        left: Stoppos.left,
        top: Stoppos.top
      };

      $.ajax({
        url: "/scrum/save",
        type: "post",
        data: model,
        success: function(data) {
          jQuery.HP({
            title: "Success!",
            message: "Saved..."
          });
        },
        error: function() {
          //  alert('error is saving');
        }
      });
    }
  });
});

I tried this to get id of current column, but it didn't work.

var trid = $(this).closest('th').attr('id'); alert(trid); 

How can I get dropped id?

  • 写回答

1条回答 默认 最新

  • duanbichou4942 2018-11-06 12:06
    关注

    If you clicked the <th> then you should get the id via the following line:

    var id=$(event.target).attr('id');
    

    (In case you click on an element withint an element that contains the event, use "currentTarget", instead of "target").

    If you click on something else, then you need to navigate there via Parent()/Child() or other measures. Do you have the HTML? And which element if HTML is returned when using $(event.target) ?

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料