2014-10-23 2 views
0

div의 내용을 여러 번 조정하고 변수에 저장할 수 있습니까? 아래 코드에서는 4 가지 변수에 차이가 없습니다. 항상 최신 내용을 표시합니다.div의 내용을 여러 번 조정하여 변수에 저장하십시오.

누군가 나를 도울 수 있습니까? 미리 감사드립니다.

$("div#ingredients h1 span").html("kokos"); 
$("div#ingredients img").attr("src", "content/coconut.jpg"); 
$("div#ingredients p").html("Kokos die wij verwerken in onze Cocosballs komt uit Indonesië. De kwaliteit van die kokos draagt bij aan de heerlijke smaak van de Cocosballs."); 
var coconutContent = $("div#ingredients"); 


$("div#ingredients h1 span").html("honing"); 
$("div#ingredients img").attr("src", "content/coconut.jpg"); 
$("div#ingredients p").html("Verse biologische honing is een onmisbaar ingrediënt in onze cocosballs, het maakt de traktatie wat frisser"); 
var honeyContent = $("div#ingredients"); 


$("div#ingredients h1 span").html("eiwit"); 
$("div#ingredients img").attr("src", "content/coconut.jpg"); 
$("div#ingredients p").html("Eiwit zorgt voor de fijne structuur van onze cocosballs en maakt ze extra luchtig"); 
var eggContent = $("div#ingredients"); 


$("div#ingredients h1 span").html("suiker"), 
$("div#ingredients img").attr("src", "content/coconut.jpg"), 
$("div#ingredients p").html("Het beetje suiker wat door onze Cocosballs zit, maakt onze Cocosballs af. Het wordt er wat zoeter door"); 
var sugarContent = $("div#ingredients"); 


$("div#ingredients").hide(); 
$(coconutContent).show(); 


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

    $(sugarContent).fadeIn(); 

}) 
+0

'$ ("div # ingredients")'는 객체에 대한 참조를 반환하므로 여기서는 동일한 jq 객체와 ID를 참조하는 네 개의 변수가 문서 컨텍스트에서 고유해야합니다. 구체적인 샘플로 무엇을 찾고 있는지 설명하는 것이 좋습니다. –

+0

에 대한 대신 당신이 원하는 것 :'var coconutContent = $ ("div # ingredients"). html();'등 ... –

+0

그래, 그런 식으로하고 싶다. 하지만 변수에 여러 규칙을 추가하려면 어떻게해야합니까? 이와 같이 : var coconutContent = $ ("div # ingredients h1 span") .html ("kokos"), $ ("div # ingredients img"). attr ("src", "content/sugar.jpg"), 등등. –

답변

0

여러 div를 만듭니다. 보여주고 싶은 것을 제외한 모든 것을 숨 깁니다. div에 원하는 다양한 컨텐츠가 아니라 동일한 div를 가리키는 4 개의 변수를 작성 중입니다.

+0

그래, 고마워,이 모든 변수를 올바르게 저장하는 방법에 대한 답을 찾지 못하면이 방법을 사용한다. 대화식 목적으로 사용하기 때문에 jQuery 파일에 다른 내용을 넣어 두는 것이 더 명확합니다. 아니면 내가 틀렸어? 나는 그것으로 슬라이드 쇼의 일종을 만들었고, 다른 내용은 페이드 인과 페이드 아웃 만하면된다. –

관련 문제