現在,所有的東西都以這個代碼運行,但我想從表格中獲取任何值(比如說3)和回顯它在名爲#popup的div中。 基本上,我想在一個php變量中具有該值,以便可以對該變量運行查詢。當我點擊一個表格行時,會顯示一個div,它應該回顯該點擊行中的任何一個字段值
簡單的解決方案將不勝感激。
HTML代碼:
<table>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</tbody>
</table>
<div id="popup">
This is the div which will be displayed when a row in table is clicked. And it should
echo any td value from the table.
</div>
的JQuery/Javascript代碼:
$(document).ready(function(){
$('table tbody tr').click(function(){
var a=[]; //takes all td values from clicked row
$(this).find('td').each(function(){
a.push($(this).text());
});
$('#popup').show();
//here the div is displayed but also any value from the array "a" should be displayed in the same div
});
});
CSS代碼:
table{
border-collapse:collapse;
}
table td{
border:1px solid black;
padding:6px;
}
#popup{
border:1px solid green;
height:95px;
width:177px;
background-color:lightblue;
color: white;
display:none;
}
它的工作原理。我可以在一個PHP變量的值?這樣我可以對該變量運行查詢。 –
如果你想發佈到php使用ajax發送。 –
我不知道該怎麼做? –