我有一个带有按钮的表,我想要的是当我单击按钮“ id = myBtn”将其值输入到输入文本字段。
<tbody>
<?php while($row = mysqli_fetch_array($queryTripulacion2)):? >
<tr>
<td><input type="checkbox" name="f[]" value=<?php echo $row[2];?>></td>
<td><?php echo $row['order'];?></td>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['last'];?></td>
<td ><?php echo $row['cod1']?></td>
<td class="nr"><?php echo $row['cod2'];?></td>
<td><?php echo $row['address'];?></td>
<td><?php echo $row['activity'];?></td>
<td><input type="button" id="myBtn" value="<?php echo $row['wanted_value']; ?>"></td>
</tr>
<?php endwhile;?>
</tbody>
这是我尝试过的,但是没有用!我希望在“ #inputM”中包含“ wanted_value”。谢谢!
$(".tablar tbody").on('click','#myBtn',function() {
$('#modal').show();
var c = $(this).closest('tr').find('td.eq(8)').text();
$("#inputM").val(c);
答案 0 :(得分:0)
.eq()
是一个函数,不是选择器的一部分。所以应该是:
var c = $(this).closest('tr').find('td').eq(8).text();
但是这行不通。 TD中没有任何文本,只有输入按钮。您需要选择按钮(而不是TD),并使用.val()
而不是.text()
。
var c = $(this).closest('tr').find('td').eq(8).children(":button").val();
但这确实使它变得过于复杂,因为您选择的按钮与您单击的按钮相同,因此应该是:
var c = $(this).val();