目前,代码仅适用于第一行,但无法处理以下行,任何想法?
if (typeof set == "undefined") {
var set = $(".url").val();
}
$(".addSkip").on('click', function() {
$(".url").val(set + $("#name").val());
});

<table>
<tr>
<td><input type="date" size="15" name="date[]" class="start_date" \>
<input type="button" size="10" value="confirm date" class="addSkip"></td>
<td>Nextdate<input type="text" value="100" id="name" size="15" name="nextdate[]" class="end_date" \> </td>
<td>traditionalmessage<textarea rows="3" cols="20" readonly class="url" name="traditionalmessage[]">traditionalmessage</textarea> </td>
<td>simplifiedmessage<textarea rows="3" cols="20" readonly class="url" name="simplified[]">simplifiedmessage</textarea> </td>
<td>engmessage<textarea rows="3" cols="20" readonly class="url" name="engmessage[]">engmessage</textarea> </td>
</tr>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
&#13;
答案 0 :(得分:0)
尝试使用classname而不是id
。并找到元素us $(this).closest('tr').find(".url")
closest()
与tr
find()
匹配 <强>更新强>
if (typeof set == "undefined") {
var set = $(".url").val();
}
$(".addSkip").on('click', function() {
$(this).closest('tr').find(".url").eq(0).val(set + $(this).closest('tr').find(".end_date").val());
});
&#13;
<table>
<tr>
<td><input type="date" size="15" name="date[]" class="start_date" \>
<input type="button" size="10" value="confirm date" class="addSkip"></td>
<td>Nextdate<input type="text" value="100" id="name" size="15" name="nextdate[]" class="end_date" \> </td>
<td>traditionalmessage<textarea rows="3" cols="20" readonly class="url" name="traditionalmessage[]">traditionalmessage</textarea> </td>
<td>simplifiedmessage<textarea rows="3" cols="20" readonly class="url" name="simplified[]">simplifiedmessage</textarea> </td>
<td>engmessage<textarea rows="3" cols="20" readonly class="url" name="engmessage[]">engmessage</textarea> </td>
</tr>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
&#13;