2011-09-08 2 views
2

현재 jquery를 사용하여 웹 사이트를 만들고 있습니다. id를 "content"로 사용하여 div를 클릭하면 스크립트가 숨겨진 스크립트를 발견했습니다. 나는 div를 보여줄 것이고 내가 지정한 것을 html로 설정할 링크가있다. 내 유일한 문제는 html 변경을 트리거하는 링크 중 하나를 선택한 다음 div 외부를 클릭하면 다른 링크를 선택하고 초기 트리거의 html 만 표시된다는 것입니다.div (jquery)의 html 값 재설정 관련 문제

스크립트가 해당 html을 올바르게 표시하도록하려면 어떻게해야합니까? 내가 값을 설정하려면 다음 코드를 사용하고

말했다 사업부 :

당신이 원하는 것을 100 % 명확하지 않고
<script> 

$("#projects").click(function() { 

    $("#content").replaceWith("This should display the projects!"); 

}); 

</script> 

<script> 

$("#resources").click(function() { 

    $("#content").replaceWith("This should display the resources!"); 

}); 

</script> 

<script> 

$("#contact").click(function() { 

    $("#content").replaceWith("This should display the contact information!"); 

}); 

</script> 
+0

당신의 설명을 나에게 어떤 이해가되지 않습니다

은 당신이 아마 찾고있는 것은 HTML() 방법이다. 너는 reword 할 수 있는다? – mrtsherman

답변

4

replaceWith 방법은 "제공된 새로운 콘텐츠와 매칭 소자들의 세트 내의 각각의 요소를 교체."것 (문서에서).

즉, 전화를 걸면 해당 페이지에 ID가 "content"인 div가 더 이상 존재하지 않아 교체되었음을 의미합니다.

http://api.jquery.com/html/

사용 예 :

$("#contact").click(function() { 

    $("#content").html("This should display the contact information!"); 

}); 
+0

예! 이게 내 문제를 해결했습니다! 설명해 주셔서 감사합니다. 해결책에 대한 분쟁에 감사 드리며 제 문제를 철저히 설명 할 수 없습니다. –

1

,

다음으로 $.replaceWith() 기능을 변경해보십시오 :

$('#content').empty() 
    .html('The is all the contact/resource/project information you want to display');