23 July 2017

JQuery: Set giá trị cho id với kiểu TEXT, HTML, VAL

JQuery Set text html val
JavaScript 2017
<!DOCTYPE html>
<html>
    <head>
        <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
        <script>
            $(document).ready(function () {
                $("#btn1").click(function () {
                    $("#test1").text("Hello world!");
                });
                $("#btn2").click(function () {
                    $("#test2").html("<b>Hello world!</b>");
                });
                $("#btn3").click(function () {
                    $("#test3").val("giai-ma.blogspot.com");
                });
            });
        </script>
    </head>
    <body>

        <p id="test1">This is a paragraph.</p>
        <p id="test2">This is another paragraph.</p>

        <p>Input field: <input type="text" id="test3" value="Mickey Mouse"></p>

        <button id="btn1">Set Text</button>
        <button id="btn2">Set HTML</button>
        <button id="btn3">Set Value</button>

    </body>
</html>

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang