2011年11月22日

jQuery checkbox checked event

jQueryでチェックボックスの状態を監視するイベントはclick eventを使う。

チェックされたかを判断するには$("#some_checkbox").is(':checked')がいい。

CoffeeScriptでのサンプルコード:

change eventも監視はできるが、取れる値は遅延されるみたいです。

The change event is sent to an element when its value changes. This event is limited to input elements, textarea boxes and select elements. For select boxes, checkboxes, and radio buttons, the event is fired immediately when the user makes a selection with the mouse, but for the other element types the event is deferred until the element loses focus.

参考:http://forum.jquery.com/topic/jquery-checkbox-checked-event

Share on Twitter Share the post
Qihuan Piao

朴 起煥

東京で働いている「外人歴」9年のソフトウェア「ライター」。いつの間にか納豆が食えるようになり、これで日本に慣れきったと思いきやまだまだ驚きが続いてる。読んだり書いたりするのが好きで、自身の経験や本から得た「何か」をここに書き出してる。最近古本屋にハマってる。

他にも英語中国語で書いてます、よろしければチェックしてみてください。