[英]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.