jQuery로 폼 처리하기 – 심화

출처: jQuery로 폼 처리하기 – 심화

Crocodile order form


Crocodile order form

script> // Maps croc species to image URLs var crocImages = { "american": "https://upload.wikimedia.org/wikipedia/commons/f/f2/Crocodylus_acutus_mexico_02-edit1.jpg", "saltwater": "https://upload.wikimedia.org/wikipedia/commons/c/ca/Crocodylus_porosus_4.jpg", "freshwater": "https://upload.wikimedia.org/wikipedia/commons/c/ce/Australia_Cairns_18.jpg" }; // When the user submits the form, // Check what species they ordered // and display an image of it $("#croc-form").on("submit", function(event) { event.preventDefault(); var $crocSpecies = $(this).find("[name=species]"); // scoped var crocSpecies = $crocSpecies.val(); var $img = $(""); $img.width(100); $img.attr("src", crocImages[crocSpecies]); $img.appendTo("body"); });

응용: 도넛 계산기

Donut Calculator

Winston eats 3 donuts a day. How many donuts will he eat in his lifetime?



Donut Calculator

Winston eats 3 donuts a day. How many donuts will he eat in his lifetime?

Leave a comment