1. 程式人生 > >jQuery-文字框內容顯示在頁面

jQuery-文字框內容顯示在頁面

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>Document</title>
    <script src="jquery-1.11.3.js"></script>
    <script>
        window.onload = function(){
            $("#btn").click(function(){
                //1、獲取 uname 的值
                var uname = $("#uname").val();
                //2、將uname的值顯示在#show中
                $("#show").html(uname);
                //3、設定#show的css樣式
                $("#show").css({
                    "font-size":"32px",
                    "color":"red",
                    "background":"yellow",
                    "font-weight":"bold"
                });
            });
        }
    </script>
 </head>
 <body>
  <p>
        使用者名稱:
        <input type="text" id="uname">
        <button id="btn">顯示</button>
    </p>
    <div id="show"></div>
 </body>
</html>