javascript - 单击父 div 时,获取子值 - 无需字符串操作

标签 javascript jquery html

如何获取子输入值;来自其父 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()

进行字符串操作

请帮忙。

最佳答案

$('#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()
});

关于javascript - 单击父 div 时,获取子值 - 无需字符串操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10216871/

相关文章:

javascript - 使用 @input 将对象数组从 Angular 模板传递到另一个组件

jquery - 仅占两行的宽度

javascript - 如何在 jQuery 数据表中选择行时检测空表

html - CSS图片div的定位

javascript - 2秒后停止同步功能

javascript - 使用 jQuery 根据 Google Geocoding API JSON 响应的类型获取值

php - 按下按钮时尝试发送主键值以编辑数据

html - CSS:动画滚动按钮

javascript - 使用php将动态css和javascript提交到mysql数据库

jquery - 我可以使用 css 或 jQuery 更改滚动速度吗?