Cấu trúc:
Mã:
$("#textfield").attr("value")
Ví dụ:
Có 1 input text nằm trong form:
Mã:
<input type="text" name="textfield" id="textfield" value="Hong Phu" />
Để lấy giá trị của nó thì đơn giản như sau:
Mã:
// Khi click submit (:submit)
$(":submit").click(function(){
                    // Nạp giá trị (value) của id="textfield" vào biến t
                    var t = $("#textfield").attr("value");
                      // Xuất biến t bằng hàm text(t) ra nơi có id="test"  (#test)
                    $("#test").text(t);
                    return false;
         });
Code đầy đủ:
Mã:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
       <script src="http://code.jquery.com/jquery-latest.js"></script>
        </script>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>jQuery Starter Kit - PHP Code Vn Group</title>
        <style type="text/css">
            a.test {
                font-weight: bold;
            }
        </style>
        <script type="text/javascript">
            $(document).ready(function(){
                // Your code goes here ========== =>
          
               
                $(":submit").click(function(){
                    var t = $("#textfield").attr("value");
                    $("#test").text(t);
                    return false;
                });
               
                // Your code goes here ========== <=
            });
        </script>
    </head>
    <body>
     
        <form id="form1" name="form1" method="post" action="">
            <p>
                <label>
                    <input type="text" name="textfield" id="textfield" value="Hong Phu" />
                </label>
            </p>
            <p>
                <label>
                    <input type="submit" name="submit" id="submit" value="Submit" />
                </label>
            </p>
        </form>
        <p>
            &amp;nbsp;
        </p>
        <div id="test">
        </div>
    </body>
</html>
Phú-Teiuns