jQuery的AJAX负荷一定的DIV [英] jquery ajax load certain div

查看:171
本文介绍了jQuery的AJAX负荷一定的DIV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单,我怎么可以检索特定的div使用jQuery阿贾克斯COMAND

  $。阿贾克斯({
      网址:test.html中,
      成功:函数(){
           $(本).addClass(完成);
      }
  });
 

像负载

  $('#targetDiv').load('HTTP://localhost/test.html #sourceDiv');
 

解决方案

如果股利是Ajax响应的一部分:

  $。阿贾克斯({
    网址:test.html的,
    数据类型:HTML,
    成功:函数(HTML){
        VAR股利= $('#sourceDiv',$(HTML))addClass('完成')。
        $('#targetDiv)HTML(DIV);
    }
});
 

my question is very simple how can I retrieve certain div with jquery ajax comand

$.ajax({
      url: "test.html",
      success: function(){
           $(this).addClass("done");
      }
  });

like with load

$('#targetDiv').load('http://localhost/test.html #sourceDiv');

解决方案

If the div is part of the AJAX response:

$.ajax({
    url: 'test.html',
    dataType: 'html',
    success: function(html) {
        var div = $('#sourceDiv', $(html)).addClass('done');
        $('#targetDiv').html(div);
    }
});

这篇关于jQuery的AJAX负荷一定的DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆