为什么我的动态表没有过滤功能?
Why doesn't my dynamic table have filtering?
我想使用下拉菜单来显示可以使用tablefilter.js(在http://tablefilter.free.fr/上找到)过滤的不同表。表显示出来,但是它们没有过滤功能。
下面是test.html的代码:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<head>
<title>Test</title>
<script type="text/javascript" language="javascript" src="TableFilter/tablefilter.js"> </script>
<script type="text/javascript">
function sel_change(choice){
if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("spn_table").innerHTML=xmlhttp.responseText;
var table1Filters = {
col_0: "select",
col_1: "select",
alternate_rows: true,
}
var tf01 = setFilterGrid(choice,table1Filters);
}
}
xmlhttp.open("GET","testphp.php?choice="+choice,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form name="frm_summaries">
<select id = "styleselect" name = "sel_choice" onchange = "sel_change(this[selectedIndex].text);">
<option>hockey</option>
<option>baseball</option>
<option>basketball</option>
</select>
</form>
<p>
<span id="spn_table"></span>
</body>
</html>
下面是testphp。php的代码:
<?php
$choice=$_GET["choice"];
if ($choice == "hockey"){
echo "<table class='"mytable TF'" id="; echo $choice; echo ">";
echo "<thead><tr>";
echo "<th>first name</th>";
echo "<th>last name</th>";
echo "</tr></thead>";
echo "<tr>";
echo "<td>Sidney</td>";
echo "<td>Crosby</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Wayne</td>";
echo "<td>Gretzky</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Mario</td>";
echo "<td>Lemieux</td>";
echo "</tr>";
echo "</table>";
} else if ($choice == "baseball"){
echo "<table class='"mytable TF'" id="; echo $choice; echo ">";
echo "<thead><tr>";
echo "<th>first name</th>";
echo "<th>last name</th>";
echo "</tr></thead>";
echo "<tr>";
echo "<td>Babe</td>";
echo "<td>Ruth</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Lou</td>";
echo "<td>Gehrig</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Mickey</td>";
echo "<td>Mantle</td>";
echo "</tr>";
echo "</table>";
} else if ($choice == "basketball"){
echo "<table class='"mytable TF'" id="; echo $choice; echo ">";
echo "<thead><tr>";
echo "<th>first name</th>";
echo "<th>last name</th>";
echo "</tr></thead>";
echo "<tr>";
echo "<td>Michael</td>";
echo "<td>Jordan</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Larry</td>";
echo "<td>Bird</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Wilt</td>";
echo "<td>Chamberlain</td>";
echo "</tr>";
echo "</table>";
}
?>
请告诉我我错过了什么。谢谢。
这个问题很可能是由于这些表是动态添加到页面的。tablefilter.js正在查找作为原始文件一部分的现有html。我建议将testphp.php选项移动到隐藏的3个不同的div中。这样,选项就已经是html的一部分了。然后,当在下拉选项中选择一个div时,只需更改所选div要显示的样式。这将避免你重写tablefilter.js的部分内容。
注:php中不需要这么多echo。每张桌子一个就可以了。哈哈。
相关文章:
- Telerik过滤功能
- 按功能过滤 ng 重复
- 通过单向绑定的过滤功能提高自定义角度下拉菜单中的角度性能
- 如何在Leaflet.js中按属性过滤TopoJSON功能
- 在可过滤的剑道移动搜索框中键入时执行功能
- jquery 使用过滤功能过滤选择
- 在现代浏览器中,有这样的自制地图和过滤功能的快捷方式吗
- 具有多选列的剑道网格自定义过滤功能
- 为什么不'我的过滤功能不起作用吗?(Javascript)
- Jquery-计数具有过滤功能的元素并显示它
- 过滤Ember中的功能
- 为什么我的动态表没有过滤功能?
- 在javascript/jquery中是否有任何内置功能来过滤邮件,如php's函数(!使用filter_var
- 如何使用jQuery过滤功能只捕获前几个字母
- 如何在不移动过滤功能的情况下将一组过滤后的数据移动到另一个工作表
- React搜索过滤功能
- 使用过滤功能清除队列
- 当链接页面加载时,使用jQuery/Javascript从外部链接应用过滤功能
- 过滤功能:使用KO挣扎
- jQuery页面加载时的过滤功能