だから私は Javascript 初心者のようなもので、HTML テンプレートから Javascript に変数を渡す方法を理解するのに苦労しています。
ユーザーが入力した検索クエリを JavaScript に渡したい。
検索クエリを取得するためのテンプレートを次に示します。
<form class="well-whatsnext form-search" style="text-align:center; border-radius:10px 10px 10px 10px; width:900px; height:0px;background-repeat:no-repeat;margin-bottom:100px;" action="/search/?q=">
<center>
<input type="text" id = "form-search" value="Search for Stuff" class="input-xxlarge search-query" style="margin: 30px 0px 0px 70px; height:50px;width:600px;font-size:20px;vertical-align:middle;text-align:center;border-radius:10px 0px 0px 10px;float:left;border-right:0px;color:grey;border-right:0px;" name="q">
</center>
<br>
</form>
これが私のJavascriptスニペットです:
$("#form-search").click(function() {
// This sends us an event every time a user clicks the button
mixpanel.track('MainSearch', {'query' : search-query, 'url' : window.location.pathname});
});
search-query
必要な正しい出力が得られないため、クエリを参照する正しい方法ではないことは明らかです。
ユーザーが検索したクエリの変数を取得するにはどうすればよいですか?