JavaScript

チェックボックス一括チェック

jqueryを使ったやり方。 <html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script> </head> <body> <input type="checkbox" id="checkbox_all" onclick="$('input[type=checkbox][name=toggle]').attr('checked', $('#checkbox_all').attr('checked'));" />…</body></html>

 自動選択するセレクトボックス

document.formname.selectname.options.selectedIndex = i;

Firefoxの場合

eventではなくeを使うのがみそ。 また、e.keyCodeとe.charCodeがある。IMEを効かせていると取れる値が違うので注意。 <script type="text/javascript"> document.onkeypress = key_Press function key_Press(e){ keycode = e.which; alert(keycode); keychar = String.fromCharCode(keycode)</script>…

キーボード入力文字を表示するJavaScript

<html> <script type="text/javascript"> document.onkeypress = key_Press function key_Press(e){ alert(String.fromCharCode(event.keyCode)); } </script> <body bgcolor="#ffffff"> </body> </html>