[英]Change a cell value of table
單擊該值時,我想更改表格的單元格值。 該單元格的默認值為“ 0”。 當我單擊該按鈕時,我想將其更改為“ 1”,將“ 1”更改為“ 0”。 我是網絡開發的新手。
如果有人可以幫助,將不勝感激。
# Init the MySQL Connection
mysql_connect("localhost", "root", "") or die(mysql_error()) ;
mysql_select_db("selfie") or die(mysql_error()) ;
# Prepare the SELECT Query
$selectSQL = 'SELECT * FROM `image_upload` INNER JOIN user_table
ON image_upload.user_id=user_table.user_id ORDER BY timestamp DESC';
# Execute the SELECT Query
if( !( $selectRes = mysql_query( $selectSQL ) ) ){
echo 'Retrieval of data from Database Failed - #'.mysql_errno().': '.mysql_error();
}else{
?>
<table border="2">
<thead>
<tr>
<th>User name</th>
<th>Category</th>
<th>Description</th>
<th>Image</th>
<th>Location</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
if( mysql_num_rows( $selectRes )==0 ){
echo '<tr><td colspan="4">No Rows Returned</td></tr>';
}else{
while( $row = mysql_fetch_assoc( $selectRes ) ){
echo "<tr>
<td>{$row['user_name']}</td>
<td>{$row['category']}</td>
<td>{$row['description']}</td>
<td ><img src='uploads/".$row['image']."'width=300px height=200px></td>
<td>{$row['location']}</td>
<td>{$row['flag']}</td>
</tr>\n";
}
}
?>
</tbody>
</table>
<td onclick = "this.innerHTML=Math.abs(parseInt(this.innerHTML) - 1);">0</td>
$("td").click(function(){
value = parseInt($(this).text());
value = (value > 0)? 0 : 1;
$(this).text(value);
});
而已。
在jQuery中,我會這樣做
$('.target').click(function () {
var target = $('.target').html();
if (target == 0) {
$('.target').html(1);
}
if (target == 1) {
$('.target').html(0);
}
})
在html中,目標td被分類為“目標”
在這里擺弄
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.