简体   繁体   English

我该如何在pageload上将默认页面加载到div中?

[英]How can I have this have a default page loaded into the div on pageload?

I need this to have a default page on load of aboutme.php but still have all the same functionality 我需要它具有关于aboutme.php的默认页面加载,但仍具有所有相同的功能

function 功能

$(function(){
    $(document).on('click', '.content-link, #profile-body a',function(e){
         e.preventDefault();// prevent browser from opening url
         $('#profile-body').load(this.href);   
    });
});

body 身体

<div id="profile-body"></div>

So before any link is clicked to load into the div; 因此,在单击任何链接以将其加载到div之前; the div has already loaded the aboutme.php page, hopefully this makes sense, and thankyou for any help in achieving this. div已经加载了aboutme.php页面,希望这是有道理的,感谢您在实现此目标方面的任何帮助。

You have this for the links: 您具有以下链接:

$(function(){
    $(document).on('click', '.content-link, #profile-body a',function(e){
         e.preventDefault();// prevent browser from opening url
         $('#profile-body').load(this.href);   
    });
});

But you need: when the page loads, 但是您需要:页面加载后,

$(document).ready(function() {
    var defaultPage = "aboutme.php";
    $('#profile-body').load(defaultPage);
});

And that's all. 就这样。 Just add this code after your code, don't replace your version. 只需在代码后添加此代码,请勿替换您的版本。

You might want to use .ajax instead of .load (when aboutme takes some time to load) 您可能要使用.ajax而不是.load(当aboutme需要一些时间来加载时)

This way you can abort the request when user clicks your content Link while aboutme is still loading: Aborting jQuery().load() 这样,当aboutme仍在加载时,当用户单击您的内容链接时,您可以中止请求: 中止jQuery()。load()

If you're loading a small snippet, this is probably overkill and you should ignore this post. 如果您正在加载一小段代码,这可能是矫kill过正,您应该忽略此帖子。

If not... just sayin 如果没有...就说

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在PageLoad上添加类之前确保元素已加载 - How to Ensure Elements have Loaded Before Adding Class on PageLoad 我有一个使用ajax调用在另一个页面的div标签中加载的html页面,我想在加载的页面上触发javascript函数吗? - I have a html page that loaded in div tag in another page using ajax call I want to trigger javascript functions on loaded page? 如何检查所有JavaScript函数是否已正确加载到页面上? - How can I check whether all JavaScript functions have loaded properly on a page? 如何仅在其所有组件都已完全加载时才显示页面? - 甲骨文顶点 - How can I display a page only when all its components have been fully loaded? - Oracle Apex 默认情况下如何打开菜单? - How can I have the menu open by default? 无论我横向滚动多少,怎样才能在页面左侧粘贴div? - How can i have a div stuck on the left side of the page no matter how much i scroll horizontally? 使用jQuery加载页面后,如何淡入div? - How can I fade a div after the page is loaded using jQuery? 如何有一个包含多个多个div的div可能是4-6-8我如何使用Jquery使它们适合页面加载 - How can have a div which contain multiple multiple div it may 4-6-8 how can i fit them on page load using Jquery 如何捕获div的位置,以便在页面重新加载时我可以拥有该位置 - How to capture position of a div so that on page reload i can have that position 如何在DIV中添加文本但看不到文本或页面上没有空格? - How can I add text inside a DIV but not have it visible or using any space on my page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM