我想在点击该值时更改表格的单元格值。该单元格的默认值为“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>
答案 0 :(得分:0)
<td onclick = "this.innerHTML=Math.abs(parseInt(this.innerHTML) - 1);">0</td>
答案 1 :(得分:0)
$("td").click(function(){
value = parseInt($(this).text());
value = (value > 0)? 0 : 1;
$(this).text(value);
});
那就是它。
答案 2 :(得分:0)
在jQuery中我会这样做
$('.target').click(function () {
var target = $('.target').html();
if (target == 0) {
$('.target').html(1);
}
if (target == 1) {
$('.target').html(0);
}
})
在html中,目标td被归类为&#34; target&#34;
小提琴here