0

複数のセレクターを複数のイベントにバインドするようにjquery関数を設定していますが、一方のイベントでのみ機能し、もう一方のイベントでは機能しないようです。スクリプトは次のとおりです。

$('input[id*=_other]').parent().siblings().children().addClass('code');
$('.code, input[id*=_other]').bind('click, keyup', function(){

  $(this).each(function(){

    if ($(this).hasClass('code')) {
      if($(this).is(':checked')){
        alert('click')
      }
      else {

      } //not working
    }

    else if ($(this).val().length > 0) {
      alert('entered')
    }

    else {

    } //working

  });
});

そして、htmlセクションは次のようになります。

<th class="gridlabel">other specify 1<input size="15" tabindex="21" name="q62_5_other" class="other_input" id="q62_5_other" type="text" value="asd"/></th>
    <td headers="q62_header1" class="gridcell"><input tabindex="22" type="radio" name="q62_5" id="q62_5_1" value="1"/></td>
    <td headers="q62_header2" class="gridcell"><input tabindex="23" type="radio" name="q62_5" id="q62_5_2" value="2"/></td>
    <td headers="q62_header3" class="gridcell"><input tabindex="24" type="radio" name="q62_5" id="q62_5_3" value="3"/></td>
    <td headers="q62_header4" class="gridcell"><input tabindex="25" type="radio" name="q62_5" id="q62_5_4" value="4"/></td>
    <td headers="q62_header5" class="gridcell"><input tabindex="26" type="radio" name="q62_5" id="q62_5_5" value="5"/></td>

つまり、開いたテキストボックスであり、その後にテーブルセルの5つのラジオボタンがすべて1行に表示されます。

5つのラジオボタンのいずれかがクリックされた場合はアラート「クリック」が表示され、開いているテキストボックスがキー入力された場合はアラート「入力済み」が表示されます。

開いているテキストボックスのアラートは確かに機能しています。ラジオボタンのアラートは、「クリック」と「キーアップ」の代わりに「.bind('クリック'、関数{...」」しかない場合にも機能します。

上記のスクリプトの修正バージョンで両方のシナリオを実現する方法がわかりませんか?

4

2 に答える 2

1

カンマは必要ありません。そのはず:

$('...').bind('click keyup', function() {...});
于 2012-09-21T05:26:50.327 に答える
0

コンマは使用しないでください...代わりに

bind('click, keyup', function(){

これを試して

bind('click keyup', function(){
于 2012-09-21T05:28:11.543 に答える