這是第四位的輸入域:獲得的價值構成另一種輸入字段
<td><input type="number" name="tour" value="12" size="2" maxlength="2"></td>
這個js dosnt工作:
var hTour = $(this).parents('tr').find('td:nth-child(4)').val();
的哪些錯誤?
這是第四位的輸入域:獲得的價值構成另一種輸入字段
<td><input type="number" name="tour" value="12" size="2" maxlength="2"></td>
這個js dosnt工作:
var hTour = $(this).parents('tr').find('td:nth-child(4)').val();
的哪些錯誤?
您的JavaScript正在獲取td
元素的值。你可能希望input
元素的值:
var hTour = $(this).closest('tr').find('td:nth-child(3) input').val();
:nth-child()
爲零指數的,所以:nth-child(0)
是第一要素,:nth-child(1)
是第二個,依此類推。
其實:
var hTour = $(this).parents('tr').find('td:nth-child(4)').val();
你正在尋找的td
內的值。但是,你需要輸入的td
喜歡裏面的值:
var hTour = $(this).parent('tr').find('td:nth-child(4) input').val();
從:nth-child() Selector API docs
指數:每個孩子的指數相匹配,從1開始,字符串 偶數或奇數或等式(例如:第n個孩子(偶數),:第n個孩子(4N))
另外
Given a single <ul> containing two <li>s, $('li:nth-child(1)') selects
the first <li> while $('li:eq(1)') selects the second.
那麼'this'指的是什麼? – tymeJV
'td'標籤沒有'value'屬性。 –