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();
})
'$ ("div # ingredients")'는 객체에 대한 참조를 반환하므로 여기서는 동일한 jq 객체와 ID를 참조하는 네 개의 변수가 문서 컨텍스트에서 고유해야합니다. 구체적인 샘플로 무엇을 찾고 있는지 설명하는 것이 좋습니다. –
에 대한 대신 당신이 원하는 것 :'var coconutContent = $ ("div # ingredients"). html();'등 ... –
그래, 그런 식으로하고 싶다. 하지만 변수에 여러 규칙을 추가하려면 어떻게해야합니까? 이와 같이 : var coconutContent = $ ("div # ingredients h1 span") .html ("kokos"), $ ("div # ingredients img"). attr ("src", "content/sugar.jpg"), 등등. –