如何使用JQuery获取li元素单击操作

时间:2014-01-18 21:36:39

标签: jquery

我正在尝试通过帖子发送li点击,但这不会发生:

<nav class="navigation">
    <ul>
        <li t="1" class="li_messages li_messages_selected">Received</li>
        <li t="2" class="li_messages">Sended</li>
        <li t="3" class="li_messages">Deleted</li>
    </ul>
</nav>

我正在使用以下jQuery代码:

$(".navigation").on('click', 'li', function () {
    $(this).siblings('li').removeClass('li_messages_selected');
    $(this).addClass('li_messages_selected');
    $(".navigation li.li_messages_selected").removeClass("li_messages_selected");
    $('li', this).addClass("li_messages_selected");
    var page = $(this).attr('p');
    var type = $(this).attr('t');
    loadData(page, type);
});

有人可以帮我解决这个问题吗?

[编辑]

function loadData(page, type){
   loading_show();
   $.ajax
   ({
      type: "POST",
      url: "charge_messages.php",
      data: {
         page:page,
         type:type,
      },
      success: function(msg)
      {
         $("#lib_container").ajaxComplete(function(event, request, settings)
         {
            loading_hide();
            $("#lib_container").html(msg);
         });
      }
   });
}

1 个答案:

答案 0 :(得分:0)

替换:

  success: function(msg)
  {
     $("#lib_container").ajaxComplete(function(event, request, settings)
     {
        loading_hide();
        $("#lib_container").html(msg);
     });
  }

使用:

  success: function(msg)
  {
      loading_hide();
      $("#lib_container").html(msg);
  }

现在有效吗?