0

如果

alert($(TheButton).parent().parent().children("td").html());

返回

<input id="Quantity" name="Quantity" 
style="width: 35px;
background-color: rgb(254, 254, 254);" type="text" value="1">  

为什么

alert($(TheButton).parent().parent().children("td").val());

返回一个空字符串?

4

1 回答 1

4

因为td元素没有值。

当你调用.children('td')你得到的是一个td元素列表。当您调用时.html(),您得到的是元素内的 HTML。在这种情况下,HTML 恰好是一个input元素。但.html()没有辨别,它只是返回那里的东西。

因此,在这种情况下,当您调用时,您调用.children('td').val()的是没有值.val()的元素。td也许您打算改为选择input元素?

alert($(TheButton).parent().parent().children("td").find("input").val());
于 2013-10-10T18:49:28.673 回答