<jQuery> テキストボックスの値取得
テキストボックスの値を取得する。
<html> <script type="text/javascript" src="jquery-2.0.3.js"></script> <script type="text/javascript"> var s; $(function(){ // HTMLロード完了 $("#button1").click(function() { s = $("#text1").val(); // 値取得 $("#output").text(s); // 出力 }); }); </script> <body> <input id="text1" type="text" /> <input id="button1" type="button" value="button" /> <div id="output"></div> </body> </html>
基本は、セレクタselector
を指定して、それに対してメソッドmethod
実行。
慣れてくるとだんだんわかってきた。