November 22, 2011

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

Qihuan Piao

(aka kinopyo) is Chinese based in Tokyo. Software writer. He shares stories inspired him in this blog. His infamous line - "I feel calm when I kill those monsters, or people (in game)" shocks his friends deeply.

He also writes in Japanese and Chinese.