如何使用 jQuery 獲取文字區域的內容?


我在這裡使用一個文字區域和一個按鈕。第一個文字區域用於使用者輸入,然後點選按鈕並在提示框中顯示該值。

示例

 演示

<html>
<head>
   <script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
      <script type="text/javascript">
         $(document).ready(function () {
            $("button").click(function () {
               var dim = $("#txt").val();
               alert(dim);
            });
         });
   </script>
</head>
<body>
<div>
<textarea id="txt" rows="5" cols="20"></textarea>
<button type="button" id="btn">Click Here</button>
</div>
</body>
</html>

更新於: 2020-06-21

596 瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.