Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从可变url到jquery load()函数中选择元素标记_Javascript_Jquery_Html - Fatal编程技术网

Javascript 如何从可变url到jquery load()函数中选择元素标记

Javascript 如何从可变url到jquery load()函数中选择元素标记,javascript,jquery,html,Javascript,Jquery,Html,我只是有一个关于语法的小问题 如果我想在变量“test”中传递我的url,但是我只需要选择html标记文章中的数据。。。我能做什么?这不起作用: $(document).ready(function() { $('a').click(function(e) { e.preventDefault(); var test = $(this).attr('href'); $('.window').load(test).find("art

我只是有一个关于语法的小问题

如果我想在变量“test”中传递我的url,但是我只需要选择html标记文章中的数据。。。我能做什么?这不起作用:

 $(document).ready(function() {
     $('a').click(function(e) {
         e.preventDefault();
         var test = $(this).attr('href');
         $('.window').load(test).find("article"); //this does'nt work, please help
     });
 });

您可以将可选的jQuery选择器传递给load函数(由URL中的空格分隔),以加载页面片段

$(document).ready(function() {
    $('a').click(function(e) {
        e.preventDefault();
        var test = $(this).attr('href');
        $('.window').load(test + ' article');
    });
});

您可以在

中找到此功能,正如我从您的问题中了解到的,您需要使用sessionStorage或localStorage而不是variable来完成您想要的任务……!:)您是否只想用
文章
的内容填充
.window