Javascript 如何隐藏优势元素?

Javascript 如何隐藏优势元素?,javascript,jquery,html,Javascript,Jquery,Html,我试图隐藏li,当我点击按钮时 它不起作用了 <li class="list-group-item jogador"> <button class="btn btn-danger excluir">Excluir</button> </li> <script> $('.excluir').click(function(){ $.ajax({ url: '/test/', method: 'post', succe

我试图隐藏
li
,当我点击
按钮时

它不起作用了

 <li class="list-group-item jogador">
 <button class="btn btn-danger excluir">Excluir</button>
 </li>


<script>
$('.excluir').click(function(){
 $.ajax({
  url: '/test/',
  method: 'post',
  success: function() {
   $('.jogador').closest().hide();
  }
 });
});
</script>
  • 排他性
  • $('.excluir')。单击(函数(){ $.ajax({ url:“/test/”, 方法:“post”, 成功:函数(){ $('.jogador').closest().hide(); } }); });

    使用
    $(this.prev().hide()进行测试但它也不起作用。

    要选择父项:

    $('.excluir').click(function(){
     var $t = $(this);//so that we can use this after the callback
     $.ajax({
      url: '/test/',
      method: 'post',
      success: function() {
        $t.parent().hide();//select our parent
      }
     });
    });
    

    您要选择父项:

    $('.excluir').click(function(){
     var $t = $(this);//so that we can use this after the callback
     $.ajax({
      url: '/test/',
      method: 'post',
      success: function() {
        $t.parent().hide();//select our parent
      }
     });
    });
    

    .jogador
    是李

    $('.excluir').click(function(){
    
     var $theButton = $(this);               // Reference the clicked button
    
     $.ajax({
      url: '/test/',
      method: 'post',
      success: function() {
          $theButton.closest("li").hide();  // and hide it's closest LI element
        }
     });
    
    });
    

    .jogador
    是李

    $('.excluir').click(function(){
    
     var $theButton = $(this);               // Reference the clicked button
    
     $.ajax({
      url: '/test/',
      method: 'post',
      success: function() {
          $theButton.closest("li").hide();  // and hide it's closest LI element
        }
     });
    
    });