在我的代码中,我可以获取对象但不能获取值。如何获取.cups
文本框的值?谢谢。
HTML:
<tr id="20">
<td class="description">CHEESE,FONTINA</td>
<td><input type="text" class="cups" value=""></td>
<td><input type="checkbox" class="breakfast"></td>
<td><input type="checkbox" class="lunch"></td>
<td><input type="checkbox" class="dinner"></td>
<td><input type="checkbox" class="snack"></td>
<td><input type="checkbox" class="favorites"></td>
<td><label class="addFood"><input type="button" class="input_text_custom input_button" value="Add"></label></td>
</tr>
JS:
$(document).ready(function () {
$('.addFood').click(function () {
var tr = $(this).parents('tr');
var foodId = tr.attr('id'); // works
var servings = tr.children('.cups'); // returns [object Object]
var servings = tr.children('.cups').val(); // returns undefined
alert(servings);
});
});