【发布时间】:2021-04-14 08:45:32
【问题描述】:
我需要有关 JavaScript/jQuery 解决方案的帮助,如何为 URL 更改的产品制作过滤器。
-
当点击复选框然后显示选中的颜色
-
选中时,更多过滤器会显示所有选中的颜色
-
如果点击“全部显示”,则显示所有颜色(取消选中所有过滤器)
-
点击过滤器将改变 URL: 红色=#f/红色; 蓝色=#f/蓝色; 红色和蓝色一起 = #f/red/blue
-
当页面打开时,检查 url 并应用过滤器
感谢托马斯的帮助
https://jsfiddle.net/tundyh1g/1/
.filterelements {
display: block;
width: 210px;
}
.red,
.green,
.blue,
.redgreen,
.redblue {
width: 50px;
height: 50px;
float: left;
margin: 10px;
}
.red {
background: #ff2600;
}
.green {
background: #a5de00;
}
.blue {
background: #0087ff;
}
.redgreen {
background: rgb(255, 38, 0);
background: linear-gradient(90deg, rgba(255, 38, 0, 1) 0%, rgba(165, 222, 0, 1) 100%);
}
.redblue {
background: rgb(255, 38, 0);
background: linear-gradient(90deg, rgba(255, 38, 0, 1) 0%, rgba(0, 135, 255, 1) 100%);
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<button type="button" name="all">Show all</button>
<input type="checkbox" name="red" value="red">red
<input type="checkbox" name="blue" value="blue">green
<input type="checkbox" name="green" value="green">blue
<hr />
<div class="filterelements">
<div class="red" rel="color:red"></div>
<div class="green" rel="color:green"></div>
<div class="blue" rel="color:blue"></div>
<div class="redgreen" rel="color:red|color:green"></div>
<div class="green" rel="color:green"></div>
<div class="red" rel="color:red"></div>
<div class="redblue" rel="color:red|color:blue"></div>
</div>
</body>
</html>
【问题讨论】:
标签: javascript jquery url filter