liyandong
V2EX  ›  问与答

JQ在ajax的请求到HTML后find查找id元素怎么找不到呢?class可以找到的。。

  •  
  •   liyandong · Sep 23, 2013 · 6393 views
    This topic created in 4669 days ago, the information mentioned may be changed or developed.
    $.ajax({
    type: 'get',
    url: location.href.split('?')[0]+'?t='+(new Date()).valueOf(),
    timeout: 9999,
    dataType: 'html',
    beforeSend: function(XMLHttpRequest) {
    XMLHttpRequest.setRequestHeader('request-type', 'loadList');
    },
    success: function(html) {
    if(typeof html != 'undefined') {
    document.title = html.match(/<title>(.*)<\/title>/)[1];
    console.log($(html).find('div'));//这里不返回id的div小盒子
    console.log($(html).find('#logo'));//这里也找不到logo这个id
    }
    },
    error: function() {
    location.replace(location.href.split('?')[0]);
    }
    });

    //-----------------------------------------------------//

    不对。是找不到body的子孙中第一层关系的div,这个是怎么回事呢?
    2 replies    1970-01-01 08:00:00 +08:00
    simple_plan
        1
    simple_plan  
       Sep 24, 2013 via Android
    会不会id重复了
    liyandong
        2
    liyandong  
    OP
       Sep 24, 2013
    @simple_plan 没有,总共就几个div的东西
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   940 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 20:59 · PVG 04:59 · LAX 13:59 · JFK 16:59
    ♥ Do have faith in what you're doing.