我们希望根据用户选择标记的内容来产生过滤后的答案,并且我们以此here为起点构建了网站online tutorial的演示。
我们通常对结果感到满意,除了它在移动设备中的呈现方式外,结果在屏幕上显示为三个,而不是一个显示在另一个显示之上。
<head>
<meta name="viewport" content ="width=device-width, initial-scale=1.0">
</head>
<style>
* {
box-sizing: border-box;
}
body {
background-color: #f1f1f1;
padding: 20px;
font-family: Arial;
}
/* Center website */
.main {
max-width: 1000px;
margin: auto;
}
h1 {
font-size: 50px;
word-break: break-all;
}
.row {
margin: 8px -16px;
}
/* Add padding BETWEEN each column (if you want) */
.row,
.row > .column {
padding: 8px;
}
/* Create three equal columns that floats next to each other */
.column {
float: left;
width: 33.33%;
display: none; /* Hide columns by default */
}
/* Clear floats after rows */
.row:after {
content: "";
display: table;
clear: both;
}
/* Content */
.content {
background-color: #ededee;
padding: 10px;
}
/* The "show" class is added to the filtered elements */
.show {
display: block;
}
/* Style the buttons */
.btn {
border: none;
outline: none;
padding: 12px 16px;
background-color: #f2f2f3;
cursor: pointer;
}
/* Add a grey background color on mouse-over */
.btn:hover {
background-color: #b8b8b9;
}
/* Add a dark background color to the active button */
.btn.active {
background-color: #666;
color: white;
}
</style>
<script>
filterSelection("all") // Execute the function and show all columns
function filterSelection(c) {
var x, i;
x = document.getElementsByClassName("column");
if (c == "all") c = "";
// Add the "show" class (display:block) to the filtered elements, and remove the "show" class from the elements that are not selected
for (i = 0; i < x.length; i++) {
w3RemoveClass(x[i], "show");
if (x[i].className.indexOf(c) > -1) w3AddClass(x[i], "show");
}
}
// Show filtered elements
function w3AddClass(element, name) {
var i, arr1, arr2;
arr1 = element.className.split(" ");
arr2 = name.split(" ");
for (i = 0; i < arr2.length; i++) {
if (arr1.indexOf(arr2[i]) == -1) {
element.className += " " + arr2[i];
}
}
}
// Hide elements that are not selected
function w3RemoveClass(element, name) {
var i, arr1, arr2;
arr1 = element.className.split(" ");
arr2 = name.split(" ");
for (i = 0; i < arr2.length; i++) {
while (arr1.indexOf(arr2[i]) > -1) {
arr1.splice(arr1.indexOf(arr2[i]), 1);
}
}
element.className = arr1.join(" ");
}
// Add active class to the current button (highlight it)
var btnContainer = document.getElementById("myBtnContainer");
var btns = btnContainer.getElementsByClassName("btn");
for (var i = 0; i < btns.length; i++) {
btns[i].addEventListener("click", function(){
var current = document.getElementsByClassName("active");
current[0].className = current[0].className.replace(" active", "");
this.className += " active";
});
}
</script>
<div class="cpContainer">
<div class="row">
<div class="col-sm-12">
<h2><font color="#164a5d">Learning resources</font></h2>
<div id="myBtnContainer">
<button class="btn active" onclick="filterSelection('all')"> Show all</button><br><br>
<b>Filter by PKSB Category</b><br>
<button class="btn" "style=background-color:red" onclick="filterSelection('organising')"> <b>1. Organising Knowledge & Information</b></button>
<button class="btn" onclick="filterSelection('knowledge')"> <b>2. Knowledge & Information Management</b></button>
<button class="btn" onclick="filterSelection('exploiting')"> <b>3. Using & Exploiting Knowledge & Information</b></button>
<button class="btn" onclick="filterSelection('skills')"> <b>4. Research Skills</b></button>
<button class="btn" onclick="filterSelection('information')"> <b>5. Information Governance & Compliance</b></button>
<button class="btn" onclick="filterSelection('records')"> <b>6. Records Management & Archiving</b></button>
<button class="btn" onclick="filterSelection('collection')"> <b>7. Collection Management & Development</b></button>
<button class="btn" onclick="filterSelection('learning')"> <b>8. Literacies & Learning</b></button>
<button class="btn" onclick="filterSelection('leadership')"> <b>Leadership & Advocacy</b></button>
<button class="btn" onclick="filterSelection('strategy')"> <b>Strategy Planning & Management</b></button>
<button class="btn" onclick="filterSelection('customer')"> <b>Customer Focus, Service Design & Marketing</b></button>
<button class="btn" onclick="filterSelection('communication')"> <b>IT & Communication</b></button>
<button class="btn" onclick="filterSelection('ethics')"> <b>Ethics & Values</b></button>
<button class="btn" onclick="filterSelection('widerlib')"> <b>Wider Library, Information & Knowledge Sector</b></button>
<button class="btn" onclick="filterSelection('widerorg')"> <b>Wider Organisation & Environment</b></button>
<button class="btn" onclick="filterSelection('career')"> <b>Career Development</b></button>
<br>
<!-- Portfolio Gallery Grid -->
所有能提供的帮助将不胜感激