社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Jquery

用jquery获取th的ID

Ezra • 5 年前 • 1566 次点击  

我有这张桌子:

  <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>

我的要求 enter image description here

我有4列积压,在制品,测试,国防部。如果我从积压工作中拖拽到测试中,我想得到拖拽列ID,也就是说,我想把它保存到数据库中。我试过这个:

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');
        }
      });
    }
  });
});

我试图获取当前列的ID,但没有成功。

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

我怎样才能拿到身份证?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38794
 
1566 次点击  
文章 [ 1 ]  |  最新文章 5 年前
Rory McCrossan
Reply   •   1 楼
Rory McCrossan    6 年前

如果你点击 <th> 然后您应该通过以下行获得ID:

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

(如果单击包含事件的元素的元素,请使用“currentTarget”,而不是“target”)。

如果您单击其他东西,那么您需要通过parent()/child()或其他度量导航到那里。你有HTML吗?如果在使用$(event.target)时返回html,则返回哪个元素?