如您所见,我的大部分示例都在此 1 页中,但希望具有不同数据的不同页面和下拉数据,但目前下拉处于警报状态,如果它可以更改过滤表格以某种方式没有写入太多很好的额外数据
目前我使用 Javascript、taffydb、slimbox2(用于图片库,这不在本示例中,因为它在正在执行的项目中运行良好,这就是为什么我只使用 [image] 而不是为此添加代码)和 jquery (1.3)[主要用于 slimbox2],我喜欢保持代码低(这就是为什么 jquery 是低版本,但如果它有助于我完成所需的任务,请不要介意更高),以便在我决定时更容易加载上传正在处理的真实项目,目前它只是在我的本地计算机上,希望下面的代码有所帮助,但并不代表我正在尝试做的项目。
使用时出现错误或无法加载
<script src="https://raw.github.com/typicaljoe/taffydb/master/taffy-min.js" type='text/plain'></script>
作为要加载的 taffy 文件,因此必须使用本地 taffy,即使它相同,但还是更喜欢拥有我自己的
找到了这个但并没有真正做我想要的并且令人困惑的是还使用 xml 并且有 2 个连接连接下拉列表,而我想要 1-3 个单独的单独的。 还有另一个例子,但它没有显示完整的页面代码只是一部分
index.html 页面
<!DOCTYPE><head><title>Test</title>
<link rel="stylesheet" href="style.css" type="text/css">
<script src="taffy.js"></script>
<script src="index1.js"></script>
<script src="index2.js"></script>
</head><form name="f">
<script>filter1 ();filter2 ();filter3 (); /*different filter(s) on different page(s)*/
table({country:"UK"/*filter1*/,area:1/*filter2*/,food:{has:"Pizza"}/*filter3*/});
</script></form>
样式.css
table {width:100%;border-collapse:collapse;}
body,table,tr,td,th {text-align:center;}
在 index1.js 页面中,可能会创建函数 filter1、filter2、filter3 和/或函数 Item1、Item2、Item3(如果可能以某种方式成为更好的代码)
var HR="<tr><td colspan='2'><hr style='width:90%;border:1px solid #000;'>";
function filter1 ()
{document.write("<SELECT NAME='s1' onChange='Item1 ()'>\
<OPTION VALUE='' selected>Country</OPTION>");
country().order('name').each(function (O1) {document.write("<OPTION VALUE='{country:"+O1.name+"}'>"+O1.name+"</OPTION>")});
document.write("</SELECT>");}
function filter2 ()
{document.write("<SELECT NAME='s2' onChange='Item2 ()'>\
<OPTION VALUE='' selected>Area</OPTION>");
area().order('name').each(function (O2) {document.write("<OPTION VALUE='{area:"+O2.name+"}'>"+O2.name+"</OPTION>")});
document.write("</SELECT>");}
function filter3 ()
{document.write("<SELECT NAME='s3' onChange='Item3 ()'>\
<OPTION VALUE='' selected>Food</OPTION>");
food().order('name').each(function (O3) {document.write("<OPTION VALUE='{Food:{has:"+O3.name+"}'>"+O3.name+"</OPTION>")});
document.write("</SELECT>");}
function Item1 ()
{for (i = 0; i < document.f.s1.length; i++) {if (document.f.s1[i].selected) {
chosen = document.f.s1[i].value}}if (chosen==0) {return false;}
alert(chosen);}
function Item2 ()
{for (i = 0; i < document.f.s2.length; i++) {if (document.f.s2[i].selected) {
chosen = document.f.s2[i].value}}if (chosen==0) {return false;}
alert(chosen);}
function Item3 ()
{for (i = 0; i < document.f.s3.length; i++) {if (document.f.s3[i].selected) {
chosen = document.f.s3[i].value}}if (chosen==0) {return false;}
alert(chosen);}
function table (tf) {TF=people().filter(tf);if(TF.count()>=1){document.write("<table>"+HR);TF.each(
function(t){country=t.country;area=t.area;name=t.name;food=t.food;document.write("<tr><td>[image]<td><table border='1' \
bordercolor='#000'><tr><td width='50%'><b>Country:</b>"+country+" <b>Area:</b>"+area+"<td width='50%'><b>Name:</b>"+
name+"<tr><td colspan='2'><b>Fav Food(s):</b> "+food.join(" - ")+"</table>"+HR)});document.write("</table>");}}
在 index2.js 中
var people=TAFFY();var country=TAFFY();var area=TAFFY();var food=TAFFY(); /*ECT*/
country.insert({name:"UK"});country.insert({name:"USA"}); /*ECT*/
area.insert({name:1});area.insert({name:2}); /*ECT*/
food.insert({name:"Pizza"});food.insert({name:"Chocolate"});food.insert({name:"Cheeseburger"});
food.insert({name:"Cheese"});food.insert({name:"Fruits"});food.insert({name:"Pasta"}); /*ECT*/
country().each(function (script) {document.write("<script src='"+script.name+".js'></script>")});
在 UK.js 文件中
people.insert({country:"UK",name:"Mark",area:1,food:["Pizza","Chocolate"]});
people.insert({country:"UK",name:"Mark",area:1,food:["Pizza","Pasta"]});
people.insert({country:"UK",name:"Mary",area:1,food:["Pasta"]});
people.insert({country:"UK",name:"John",area:2,food:["Pizza","Chocolate","Pasta"]});
people.insert({country:"UK",name:"Matthew",area:2,food:["Cheeseburger"]});
//ECT
在 USA.js 文件中
people.insert({country:"USA",name:"Luck",area:1,food:["Pizza","Cheese"]});
people.insert({country:"USA",name:"Luck",area:1,food:["Pizza","Chocolate"]});
people.insert({country:"USA",name:"Lucy",area:1,food:["Pasta","Fruits"]});
people.insert({country:"USA",name:"Adam",area:2,food:["Pizza","Chocolate","Pasta","Cheeseburger"]});
people.insert({country:"USA",name:"Anna",area:2,food:["Fruits","Cheese"]});
//ECT
我知道我可以使用普通文本进行过滤,但我会将表格插入到具有不同 filer1 和/或 filter2 和/或 filter3 的不同页面中,或者我可能有 1 个过滤器仅使用文本,而其他 1 和/或 2 个依赖于下拉列表,可能有 1-2 页,所有 3 个过滤器都依赖于下拉列表