主に備忘録

基本的には自分用の備忘録っぽいもの。

jQueryのチェックボックスのお話

{section name=list loop=$data}
  <input type="checkbox" name="chk" id="chk_{$smarty.section.list.index}" value="{$smarty.section.list.index}" />
{/section}

みたいに作成した一覧で、どこかがチェックされた時の処理

$('input[name="chk"]').index(this).val();

とか

$('input[name="chk"]').val()[index(this)];

とかダメなことをやっていたんだけど、

$('input[name="chk"]').change(function() {
    // value取得
    this.value;
    // チェック状態(true or false)
    this.checked;
}

これだけで大丈夫でした。

ちなみに、何番目か知りたい時は

$('input[name="chk"]').index(this);

あと、input は * でも動く。