jquery仅使用选择器基于href加载



这里是新手。

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

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

$('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? */
});

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

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

最新更新