jQuery3で、セレクトボックスの選択された項目のvalueを取得します。
【手順】
1.『jQuery3.1.0のダウンロード方法』の手順で、jQuery3.1.0をダウンロードしておきます。
2.『index.html』というファイルを作成。
3.『index.html』を以下の様に入力。
<!doctype html>
<html>
<head>
<script src="jquery-3.1.0.min.js"></script>
<script>
$(function() {
$("#button").click(function(){
$("#spn").html($("#sel").val());
});
});
</script>
</head>
<body>
<button id="button">表示</button>
<select id="sel">
<option value="aaa">あああ</option>
<option value="iii">いいい</option>
<option value="uuu">ううう</option>
</select>
選択されている項目のvalue=『<span id="spn"></span>』
</body>
</html>
4.ダウンロードした『jquery-3.1.0.min.js』と『index.html』を同一ディレクトリに配置します。
5.『index.html』をブラウザで開きます。
6.以下の様に表示されれば成功です。
以上です。

0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。