【问题标题】:jquery load base on href with the selector onlyjquery 仅使用选择器基于 href 加载
【发布时间】:2016-08-30 17:09:46
【问题描述】:

这里是新手。

我刚刚学习了如何从另一个页面(相同域)中的特定 div 中获取内容并将其加载到当前页面中。

现在我正在尝试获取 jquery 代码,以根据页面的 url 链接从特定的 div id 中获取内容。这是我目前拥有的代码,与 this question 类似。

$('a.link').click(function() {
    $("#div").load($(this).attr("href")); /* how to only load the #div id, based on the <a>'s href link to the page? */
});

【问题讨论】:

    标签: jquery hyperlink load href


    【解决方案1】:

    传入要加载内容的元素的选择器,例如:

    $('a.link').click(function() {
        var url  = $(this).attr("href") + " #yourDivID";
        $("#div").load(url);
    });
    

    【讨论】:

      猜你喜欢
      • 2016-08-14
      • 1970-01-01
      • 2012-06-12
      • 1970-01-01
      • 1970-01-01
      • 2017-11-19
      • 2014-07-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多