【问题标题】:find head tag from ajax response从ajax响应中找到head标签
【发布时间】:2013-06-04 20:22:49
【问题描述】:

我搜索了这个简单的主题,但我找不到任何东西,抱歉。我需要问你。

我从 ajax 获得成功响应,只对“.someclass”部分感兴趣,如下代码所示:

<code>
function TITO(){
    $.ajax({
    url: 'www.tito.com/index.html',
    success:
    function(response){
            $divvy = $(response).find('.someclass');
    $('#finaldiv').html($divvy);
            },
      });
};
</code>

但问题是 .someclass 是一个表格,我得到它完全没有格式(没有样式),只是保持它的结构(表格 tbody tr th 等)。

我想要的是保持原始格式,并且我知道这些说明位于 ajaxed index.html 的 head 标签上(链接的 css 文件或仅在那里指定)。

如何在我的响应中也获取 head 标签,然后在其后附加 $divvy,以便表格显示样式?

我知道获取类 (.class) 或 id (#id),但我不知道如何获取没有 id 或类的标签 :)

非常感谢。 格雷茨, 塞尔吉奥。

【问题讨论】:

    标签: jquery ajax tags response head


    【解决方案1】:
    $(response).find('head');
    

    来自 jquery 的“find”方法可以作为一个选择器,就像你有你的 fint ('.someclass")。你在那里使用了一个带有点的类的 css 选择器。你可以使用 # 表示你提到的 id之前,您可以使用 'nothing' 作为标签。您可以阅读有关 css 选择器的更多信息:https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started/Selectors

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-03
      • 1970-01-01
      • 2014-10-09
      • 2014-03-23
      • 2021-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多