题
我已经忘记了之前更改ID属性的尝试。如果请求=== 0,有没有办法让内容自动加载?而不是点击功能。
<script language="javascript">
var requests = 10;
function request(self)
{if(self.href != "#")
requests -= 1;
if(requests === 0)
var pageid = function () {
var thisID = null;
$('#step').click(function () {
thisID = this.id;
$('#content').animate({
height: getPageHeight()
},
700, function () {
$('#next-page').fadeIn(500);
$('#content-' + thisID).fadeIn(500, function () {});
});
return false;
});
};
$(window).load(pageid);
function getPageHeight() {
var windowHeight;
if (self.innerHeight) windowHeight = self.innerHeight;
else if (document.documentElement && document.documentElement.clientHeight) windowHeight = document.documentElement.clientHeight;
else if (document.body) windowHeight = document.body.clientHeight;
return windowHeight;
}}
</script>
解决方案
尝试包装所有代码:
$(document).ready(function() {
// your code
}
当代码在页面加载时运行时,您会遇到您正在寻找的内容尚未准备好使用的情况(甚至可能尚未下载)。因此,请确保在运行代码之前等到页面加载完毕。
修改强>
可能是“$(window).load(pageid);”只是错误的代码,但是如果事情仍然不起作用,你必须更加具体地了解你的目标。
这样的事情:
<script language="javascript">
var requests = 10;
$(document).ready(function() {
// Your code here
// $(window).load(pageid);
});
function request(self)
{if(self.href != "#")
requests -= 1;
if(requests === 0)
var pageid = function () {
var thisID = null;
$('#step').click(function () {
thisID = this.id;
$('#content').animate({
height: getPageHeight()
},
700, function () {
$('#next-page').fadeIn(500);
$('#content-' + thisID).fadeIn(500, function () {});
});
return false;
});
};
function getPageHeight() {
var windowHeight;
if (self.innerHeight) windowHeight = self.innerHeight;
else if (document.documentElement && document.documentElement.clientHeight) windowHeight = document.documentElement.clientHeight;
else if (document.body) windowHeight = document.body.clientHeight;
return windowHeight;
}}
</script>
其他提示
尝试在load事件中使用匿名函数,如下所示:
$(window).load(function() {
if(requests === 0)
pageid(); // or whatever you need
});
但首先从代码中删除 if(requests === 0)
条件。
不隶属于 StackOverflow