87,910
社区成员
发帖
与我相关
我的任务
分享
var data=[
{
A:'农民',
B:'小姐',
C:'大哥',
D:'包大',
E:0
},
{
A:'农民工',
B:'小姐',
C:'大哥哥',
D:'包大',
E:1
},
{
A:'农民工',
B:'小姐姐',
C:'大哥哥',
D:'包大',
E:2
},
{
A:'农民',
B:'小姐',
C:'大哥',
D:'包大人',
E:3
},
{
A:'农民工',
B:'小姐姐',
C:'大哥哥',
D:'包大人',
E:4
},
{
A:'农民',
B:'小姐',
C:'大哥哥',
D:'包大',
E:5
},
{
A:'农民',
B:'小姐姐',
C:'大哥哥',
D:'包大',
E:6
},
{
A:'农民工',
B:'小姐',
C:'大哥',
D:'包大人',
E:7
}
]
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<div>
A
<select>
<option>农民</option>
<option>农民工</option>
<option>不限</option>
</select>
</div>
<div>
B
<select>
<option>小姐</option>
<option>小姐姐</option>
<option>不限</option>
</select>
</div>
<div>
C
<select>
<option>大哥</option>
<option>大哥哥</option>
<option>不限</option>
</select>
</div>
<div>
D
<select>
<option>包大</option>
<option>包大人</option>
<option>不限</option>
</select>
</div>
</body>
</html>
if(){
if(){
if(){
if(){}
else{}
}
else{}
}
else{}
}
else{}
..........
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<div>
A
<select>
<option>农民</option>
<option>农民工</option>
<option>不限</option>
</select>
</div>
<div>
B
<select>
<option>小姐</option>
<option>小姐姐</option>
<option>不限</option>
</select>
</div>
<div>
C
<select>
<option>大哥</option>
<option>大哥哥</option>
<option>不限</option>
</select>
</div>
<div>
D
<select>
<option>包大</option>
<option>包大人</option>
<option>不限</option>
</select>
</div>
<div id="text"></div>
<script type="text/javascript">
var data=[
{
A:'农民',
B:'小姐',
C:'大哥',
D:'包大',
E:0
},
{
A:'农民工',
B:'小姐',
C:'大哥哥',
D:'包大',
E:1
},
{
A:'农民工',
B:'小姐姐',
C:'大哥哥',
D:'包大',
E:2
},
{
A:'农民',
B:'小姐',
C:'大哥',
D:'包大人',
E:3
},
{
A:'农民工',
B:'小姐姐',
C:'大哥哥',
D:'包大人',
E:4
},
{
A:'农民',
B:'小姐',
C:'大哥哥',
D:'包大',
E:5
},
{
A:'农民',
B:'小姐姐',
C:'大哥哥',
D:'包大',
E:6
},
{
A:'农民工',
B:'小姐',
C:'大哥',
D:'包大人',
E:7
}
];
var select = [...document.getElementsByTagName("select")];
const proxy=new Proxy({},{
set(target,key,value){
Reflect.set(target,key,value);
(Object.keys(proxy).length==select.length)&&(alert(filter()));
return true;
},
get(target,key){
return Reflect.get(target,key);
}
});
function filter(){
return data.filter(function(item){
let keys=Object.keys(proxy);
for(let key of keys){
if(proxy[key] != '不限' && item[key] != proxy[key]){
return false;
}
}
return true;
}).map(item=>item.E);
}
function getValue(){
const div= this.parentNode,
key=div.childNodes[0].nodeValue.replace(/\s/g,'');
proxy[key]=this[this.selectedIndex].innerHTML;
}
function init(){
for(let s of select){
getValue.call(s);
s.onchange=getValue;
}
}
init();
</script>
</body>
</html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<div>
A
<select onchange="filter()">
<option>农民</option>
<option>农民工</option>
<option>不限</option>
</select>
</div>
<div>
B
<select onchange="filter()">
<option>小姐</option>
<option>小姐姐</option>
<option>不限</option>
</select>
</div>
<div>
C
<select onchange="filter()">
<option>大哥</option>
<option>大哥哥</option>
<option>不限</option>
</select>
</div>
<div>
D
<select onchange="filter()">
<option>包大</option>
<option>包大人</option>
<option>不限</option>
</select>
</div>
<div id="text"></div>
<script type="text/javascript">
var data=[
{
A:'农民',
B:'小姐',
C:'大哥',
D:'包大',
E:0
},
{
A:'农民工',
B:'小姐',
C:'大哥哥',
D:'包大',
E:1
},
{
A:'农民工',
B:'小姐姐',
C:'大哥哥',
D:'包大',
E:2
},
{
A:'农民',
B:'小姐',
C:'大哥',
D:'包大人',
E:3
},
{
A:'农民工',
B:'小姐姐',
C:'大哥哥',
D:'包大人',
E:4
},
{
A:'农民',
B:'小姐',
C:'大哥哥',
D:'包大',
E:5
},
{
A:'农民',
B:'小姐姐',
C:'大哥哥',
D:'包大',
E:6
},
{
A:'农民工',
B:'小姐',
C:'大哥',
D:'包大人',
E:7
}
];
var select = document.getElementsByTagName("select");
function filter() {
var g = {
A:select[0].options[select[0].selectedIndex].text,
B:select[1].options[select[1].selectedIndex].text,
C:select[2].options[select[2].selectedIndex].text,
D:select[3].options[select[3].selectedIndex].text
};
var arr = [];
dataFor: for (var i = 0; i < data.length; i++) {
for (var n in g)
if (g[n]!="不限" && g[n]!=data[i][n])
continue dataFor;
arr.push(data[i].E);
}
document.getElementById("text").innerHTML = arr;
}
</script>
</body>
</html>