使用jQuery Load获取页面的特定部分 [英] Using jQuery Load to get certain part of a page

查看:91
本文介绍了使用jQuery Load获取页面的特定部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部, 我正在使用Wordpress,所以我知道主要内容在以下div范围内:

All, I'm using Wordpress so I know the main content falls within the following div:

<div id="content" role="main">

我正在尝试使用jQuery加载功能仅显示那些标签之间的内容.我该如何说内容的ID,但要说的是main的角色?

I'm trying to use the jQuery load function to display only the content in between those tags. How can I say the id of content but the role of main?

我尝试执行以下操作:

page_url = $(this).attr("href");
$("#menu_content").load(page_url + ' #content main');

这不会显示任何内容.有关如何执行此操作的任何想法?谢谢!

This doesn't display anything though. Any ideas on how to do this? Thanks!

推荐答案

尝试一下:

 $("#menu_content").load(page_url + ' #content[role="main"]');

我正在使用属性选择器,但只有在不同情况下您具有不同的角色"时才能使用它,但在ID选择器中添加任何内容确实没有道理

Am using an Attribute selector but only sense of using this would be if you have different "role" under different circumstances but it really makes no sense adding anything to an ID selector

http://api.jquery.com/category/selectors/

如果只希望#content中包含内容,请使用$ .get

If you want only what is inside #content use $.get

  $.get(page_url, function(data){
   $("#menu_content").html( $(data).find('#content').html());
  })

这篇关于使用jQuery Load获取页面的特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆