Javascript 如果选中行,如何获取特定单元格的值?
我有一个HTML表格。我需要得到具体的单元格值,如果列被选中!每行我都有一个复选框Javascript 如果选中行,如何获取特定单元格的值?,javascript,php,jquery,datatable,Javascript,Php,Jquery,Datatable,我有一个HTML表格。我需要得到具体的单元格值,如果列被选中!每行我都有一个复选框 <table id="tabellaOrdinaFarmaci" class="table table-striped table-bordered" cellspacing="0" width="100%"> <thead> <tr> <th>Codice Farmac
<table id="tabellaOrdinaFarmaci" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Codice Farmaco</th>
<th>Nome Farmaco</th>
<th>Quantità </th>
<th>Quantità di alert</th>
<th>Stato</th>
<th>Quantità da ordinare</th>
<th></th>
</tr>
</thead>
</thead>
<tbody>
<?php
foreach ($query as $row):
$quantitaDaOrdinare = $row->alert - $row->quantita;
if ($quantitaDaOrdinare > 0) {
?>
<tr id="<?php echo $row->aic; ?>" >
<td ><?php echo $row->aic; ?></td>
<td name="nomeFarmac"o><?php echo $row->denominazione ?></td>
<td><?php echo $row->quantita; ?></td>
<td><?php echo $row->alert; ?></td>
<td><?php echo $row->stato; ?></td>
<td>
<input type="text" class="form-control auto" name="codiceFarmaco" value="<?php echo $quantitaDaOrdinare ?>"/>
</td>
<td> <label>
<input type="checkbox" name="checkBox" value="<?php echo$row->aic; ?> ">
</label></td>
</tr>
<?php
} else {
}
endforeach;
?>
</tbody>
但是nome是一个空数组!有什么想法吗?提前谢谢 我觉得这是打字错误
<td name="nomeFarmac"o><?php echo $row->denominazione ?></td>
可以为复选框设置自定义属性,并在此属性中设置值。 像这样:
<input type="checkbox" name="checkBox" value="<?php echo$row->aic; ?> " customattr="<?php echo $row->denominazione ?>">
checkbox还有我使用的另一个属性:df对于checkbox的get属性,我使用这个变量aicFarmaco=$('input[type=checkbox]:checked').map(函数(u,el){return$(el).val();}).get();但现在我需要得到特定单元格的文本!这样,数组是空的@ermanno.tedeschi您不能直接使用
.map()
,您需要创建数组形式的值,然后使用.map()
。好的,但我需要在单击外部按钮时获取所有文本!要获取哪个单元格文本??具有name=“nomeFarmaco”的单元格
<td name="nomeFarmaco"><?php echo $row->denominazione ?></td>
var name = [];
$('input[name="checkBox"]').click(function(){
if($(this).is(':checked')) {
name.push($(this).parent().parent().siblings('td[name="nomeFarmaco"]').text());
} else {
var index = name.indexOf(name);
name.splice(index, 1);
}
console.log(name);
});
<input type="checkbox" name="checkBox" value="<?php echo$row->aic; ?> " customattr="<?php echo $row->denominazione ?>">
function getValue(){
var nome = $('input[name="checkBox"]:checked').attr('customattr');
return nome;
}