jquery1.html 3.47 KB
<!DOCTYPE html>
<html lang="ko">

<head>
    <meta charset='utf-8'>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

    <body>
        <div class="section">
            <ul id="fruits">
                <li>Apple</li>
                <li>Orange</li>
                <li>Melon</li>
            </ul>
        </div>
        <div class="section">
            <a href="http://www.google.com">Google</a>
            <a href="http://www.apple.com">Apple</a>
            <a href="http://www.microsoft.com">Microsoft</a>
            <a href="http://www.oracle.com">Oracle</a>
        </div>
        <div class="section">
            <form id="test">
                <input type="text" name="id" id="id"><br>
                <input type="password" name="pwd" id="pwd"><br>
                <select id "channel" name="channel">
                <option value ="kbs">KBS</option>
                <option value ="mbc">MBC</option>
                <option value ="sbs">SBS</option>
            </select>
                <p>
                    <input type="checkbox" name="hobby" value="baseball">야구
                    <input type="checkbox" name="hobby" value="basketball">농구
                    <input type="checkbox" name="hobby" value="soccer">축구
                </p>
                <p>
                    <input type="button" id="btn1" value="버튼1">
                    <input type="button" id="btn2" value="버튼2">
                    <input type="button" id="btn3" value="버튼3">
                </p>
            </form>
        </div>
        <div id="result">
            <h3> RESULT </h3>
        </div>

        <script type="text/javascript">
            $(function () {
                console.log($("#fruits").html());
                console.log($("#fruits").text());
                console.log($("#fruits").val());
                $("#result").append($("#fruits").html() + "<p>");
                $("#result").append($("#fruits").text() + "<p>");

                console.log($("channel").val());
                $("#result").append($("channel").val() + "<p>");

                console.log($("a:last").css("margin-top"));
                $("#result").append($("a:last").css("margin-top") + "<p>");

                $("a").each(function (idx) {
                    $("#result").append(("a" + idx + ":" + $(this).attr("href") + "<br>"));
                })

                $("#id").val("아이디");
                $("#pwd").val("123");

                $("input[type='checkbox']").filter("[value='soccer']").attr('checked', 'checked');

                $("#fruits").find("li:first").text("사과");

                $("#btn1").val("toggle").click(function () {
                    $("div.section:first").toggle();
                });

                $("#btn2").val("slide up").click(function () {
                    $("div.section:first").slideUp();
                });


                $("#btn3").val("slide down").click(function () {
                    $("div.section:first").slideDown();
                });

                $("div.section").mouseover(function () {
                    $(this).css("background", "#f8dff5");
                });

                $("div.section").mouseout(function () {
                    $(this).css("background", "#ffffff");
                });

                $("#channel").change(function () {
                    alert("You Selected '" + $(this).val() + "'");
                });
            });
        </script>

    </body>

</html>