1

child-input 値を取得するにはどうすればよいですか。親divのクリックイベントから-

ダイナミック HTML

<div class="tableRowOdd">
  <input type="hidden" value="28"> 

  04/11/2012
</div>

JS

$('#historyContainer .tableRowOdd').live( 'click', function(e) {

     // Here I want to get the hidden-input's value directly  
     // something like- $(this+'input').val()
     console.log( $(this) );

});

$(this).html()から文字列操作を行いたくない

助けてください。

4

4 に答える 4

3
$('#historyContainer .tableRowOdd').live( 'click', function(e) {
     console.log( $(this).find('input').val() ); // or .text()
});

これはすべての入力を繰り返すことに注意してください。最初のものだけが必要な場合:

$('#historyContainer .tableRowOdd').live( 'click', function(e) {
     console.log( $(this).find('input').first().val() ); // or .text()
});
于 2012-04-18T19:50:56.740 に答える
2

$(this).find('input').val()値を返す必要があります。

注: jQuery 1.7を使用している場合、または古いバージョンで.on使用している場合は、incaseを使用してください。推奨される機能ではありません。.delegate.live

.delegate古いバージョンに使用して、

$('#historyContainer').delegate('.tableRowOdd', 'click', function(e) {
     $(this).find('input').val()
     console.log( $(this) );
});

.onFor jQuery 1.7を使用して、

$('#historyContainer').on('click', '.tableRowOdd', function(e) {
     $(this).find('input').val()
     console.log( $(this) );
});
于 2012-04-18T19:51:27.537 に答える
2

これはjQueryを介して可能です。

$('#historyContainer .tableRowOdd').live( 'click', function(e) {

     // if you have more inputs and wanna get the hidden 
     console.log( $(this).find('input[type="hidden"]').val() );
});
于 2012-04-18T19:51:51.827 に答える
1

あなたはこれを行うことができます。

$(this).find('input').val()
于 2012-04-18T19:50:54.713 に答える