如何在sql生成的表中隐藏列?(php+jquery)
How to hide a column in sql generated table? (php+jquery)
查看了各种解决方案,但无法解决。到目前为止,我已经实现的内容,只有第一行被隐藏,而列的 id 始终保持不变。你能告诉我需要改变什么吗?
JAVASCRIPT:
<script>
$(document).on("pagecreate","#pageone",function(){
$("button").click(function(){
var theID = $(this).attr('id');
$("#"+theID).slideToggle("slow");
$("table, tr,th#"+theID).slideToggle("slow");
$("table, tr,td#"+theID).slideToggle("slow");
});
/*
$("button").click(function(){
var theID = $(this).attr('id');
$("#"+theID).slideDown("slow");
$("td.#"+theID).slideDown("slow");
});
*/
});
</script>
表查询
$query = "select * from $table_select";
$result = mysql_query($query);
echo "<table id = 'table-1'>";
$num_columns = mysql_num_fields($result);
echo "<tr>";
for ($i = 0; $i < $num_columns; $i++)
{
echo "<th id='".$i."'>";
$meta = mysql_field_name($result, $i);
if($i == 0) {
$arg1 = $meta;
}
$field_name[] = $meta;
echo "$meta</th>";
}
$k = 0;
while($table = mysql_fetch_array($result)) {
$v[] = $table[0];
echo "<tr class = 'hid_tr'>";
for ($i = 0; $i < $num_columns; $i++) {
echo "<td id='".$field_name[$i]."'>{$table[$i]}</td>";
if($i == $num_columns-1) {
echo '<td><form action="'.$_SERVER['PHP_SELF'].'" method="post"> <input type="hidden" id="quoteid" name="quoteid" value='.$v[$k].' /><input type="hidden" id="db" name="db" value='.$db_select.' /> <input type="hidden" id="table" name="t" value='.$table_select.' /> <input type="hidden" id="field" name="field" value='.$arg1.' /> <input type="submit" name="formDelete" id"formDelete" value="" style="background-color:#f00;color:#fff;"/></form></td>';
}
}
echo "</tr>";
$k += 1;
}
echo '<tr>';
for ($i = 0; $i < $num_columns; $i++) {
//echo '<a href="" id="'.$field_name[$i].'">Slide up</a>';
echo '<td><button id="'.$field_name[$i].'">Toggle '.$field_name[$i].'</button></td>';
}
echo '</tr>';
/*
echo '<tr>';
for ($i = 0; $i < $num_columns; $i++) {
//echo '<a href="" id="'.$field_name[$i].'">Slide Down</a>';
echo '<td><button id="'.$field_name[$i].'">Slide down</button></td>';
}
echo '</tr>';
*/
echo "</table>";
切换按钮
echo '<tr>';
for ($i = 0; $i < $num_columns; $i++) {
//echo '<a href="" id="'.$field_name[$i].'">Slide up</a>';
echo '<td><button id="'.$field_name[$i].'">Toggle '.$field_name[$i].'</button></td>';
}
echo '</tr>';
谢谢!
如果您的意思是您希望在有人单击顶行第 3 个 td 中的按钮时隐藏所有行的第 3 个 td,那么您需要执行以下操作:
创建标头
echo '<tr>';
for ($i = 0; $i < $num_columns; $i++) {
//The button calls a function with the proper position
echo '<td id="hideableHeader' . $i . '"><button onclick="hide(' . $i . ');">Toggle '.$field_name[$i].' </button></td>';
}
echo '</tr>';
使用数据创建列
在这里,您为每个TD提供一个id,该id组合其行和列索引,如下所示:
'<td id="hideable_' . $rowNum . '_' . $colNum . '">datahere</td>';
并跟踪总行数。
隐藏(这是一个javascript函数)
function hide(colNum)
{
//This is the header which will store its state for toggling
var header = document.getElementById( "hideableHeader" + colNum );
//Hide all of these tds starting after the first header row
for ( var row = 0; row < totalRows; row++ )
{
for ( var col = 0; col < totalCols; col++ )
{
var column = document.getElementById( "hideable_" + row + "_" + col );
//Is hidden, show it
if ( header.isHidden === true ) column.style.visibility = "visible";
//Hide it
else column.style.visibility = "hidden";
}
}
}
相关文章:
- 分部隐藏在jquery中不起作用
- PHP/JQUERY-显示json的每个子数组
- 如何避免试图用php+jquery显示php起始页的无限循环
- PHP Jquery选项卡:内容加载到一个选项卡's面板
- onClick按钮不工作javascript/php/jquery mobile
- 无法根据用户在编辑窗口中的输入显示/隐藏jtable jquery字段
- URL PHP/jQuery的链接预览
- 使用 php/jquery 动态更新单个模态
- PHP jQuery使用多个单词传递值
- 为显示/隐藏消息 Jquery 添加计时器 intervar
- PHP/JQUERY定义包含的页面
- PHP/Jquery-在PHP函数中呼应Jquery
- PHP-Jquery-简单模式的开放数据
- (php/jquery)根据另一个选中的复选框值隐藏和显示复选框
- 添加<tr>元素到动态表,动态不刷新页面,php-jquery
- 意外的PHP/jQuery/JSON交互差异
- jqgrid子网格row_id空格不起作用PHP jquery
- 如何显示/隐藏 PHP 文件中的 html 消息
- 如何在sql生成的表中隐藏列?(php+jquery)
- PHP使用PHP jquery ajax显示和隐藏数据