jQuery3で、画面表示時に入力項目にフォーカスします。⇒この件のまとめ。
このサンプルは以下のフォーカスに対応しています。
※inputタグ。
※inputタグのhiddenは飛ばす。
※inputタグのdisplay:noneは飛ばす。
※selectタグ。
※selectタグのdisplay:noneは飛ばす。
【手順】
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(){
$("input:visible,select:visible").eq(0).focus();
});
</script>
</head>
<body>
<select style="display: none;">
<option>あああ</option>
<option>いいい</option>
<option>ううう</option>
</select>
<select>
<option>かかか</option>
<option>ききき</option>
<option>くくく</option>
</select>
<input type="hidden" />
<input type="text" style="display: none;" />
<input type="text" />
<input type="text" />
</body>
</html>
4.ダウンロードした『jquery-3.1.0.min.js』と『index.html』を同一ディレクトリに配置します。
5.『index.html』をブラウザで開きます。
6.以下の様に表示されれば成功です。
以上です。

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