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