2009-09-12 4 views
0

ID 속성을 변경하려고 시도한 적이 있습니다. 요청이 === 0 일 경우 자동로드 아래에 콘텐츠를 만들 수있는 방법이 있습니까? 클릭 기능이 필요하지 않습니다.jQuery로 자동로드 할 DIV 얻기

<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> 
+0

'if (requests === 0)'의도적입니까? 냄새가 난다. – strager

답변

1

봅니다이있는 모든 코드를 포장 : 당신은 그냥 찾고있는 내용이 아닌 곳

$(document).ready(function() { 
    // your code 
} 

코드 그냥 페이지가로드로 실행

, 당신은 상황에 실행 사용할 준비가되어 있습니다 (그리고 아직 다운로드되지 않았을 수도 있음). 따라서 코드를 실행하기 전에 페이지가로드 될 때까지 기다려야합니다.

편집

그것은 될 수 "$ (창) .load (페이지 id);" 여전히 잘못된 코드 일 뿐이지 만 여전히 문제가 해결되지 않으면 목표에 대해 구체적으로 설명해야합니다. 이 같은

뭔가 :

<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> 
+0

내가 좋아하는대로 작동하지 않았다. – Homework

+0

귀하의 의견이 실제로 무엇을 의미하는지 모르겠습니다. 함수를 래핑 할 필요는 없으며 브라우저가 발견 한 코드를 단지 래핑하면됩니다. –

1

시도는 다음과 같이 당신의로드 이벤트에 익명 기능을 사용하려면 :

$(window).load(function() { 
    if(requests === 0) 
     pageid(); // or whatever you need 
}); 

하지만 먼저 코드에서 if(requests === 0) 조건을 제거합니다.

관련 문제