テキストボックス値を取得するには、jQuery

val()

関数を使用します。

例えば、

  1. $( ‘input:textbox’). val() – テキストボックスの値を取得します.

  2. $( ‘input:textbox’). val( “new text message”) – テキストボックスの値を設定します.

テキストボックスの例

<html>
<head>
<title>jQuery get textbox value example</title>

<script type="text/javascript" src="jquery-1.3.2.min.js"></script>

</head>

<body>

<h1>jQuery get textbox value example</h1>

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-format="fluid"
     data-ad-layout="in-article"
     data-ad-client="ca-pub-2836379775501347"
     data-ad-slot="6894224149"></ins>
<script>
     (adsbygoogle = window.adsbygoogle ||[]).push({});
</script><h2>TextBox value : <label id="msg"></label></h2>

<div style="padding:16px;">
    TextBox : <input type="textbox" value="Type something"></input>
</div>

<button id="Get">Get TextBox Value</button>
<button id="Set">Set To "ABC"</button>
<button id="Reset">Reset It</button>

<script type="text/javascript">
    $("button:#Get").click(function () {

    $('#msg').html($('input:textbox').val());

    });

    $("button:#Reset").click(function () {

    $('#msg').html("");
    $('input:textbox').val("");

    });

    $("button:#Set").click(function () {

    $('input:textbox').val("ABC");
    $('#msg').html($('input:textbox').val());

    });

</script>

</body>
</html>