我只是 jquery 的初学者。我想为复选框提出搜索建议。
我有这段代码建议基于标签的搜索
function studentFunction() {
var input, filter, form, label, a, i;
input = document.getElementById("studentInput");
filter = input.value.toUpperCase();
form = document.getElementById("studentUL");
label = form.getElementsByTagName("label");
for (i = 0; i < label.length; i++) {
a = label[i].getElementsByTagName("a")[0];
if (a.innerHTML.toUpperCase().indexOf(filter) > -1) {
label[i].style.display = "";
} else {
label[i].style.display = "none";
}
}
}
我有这段代码可以将复选框从 php 打印到 HTML
echo"<input type=\"checkbox\" name=\"check_list[]\" value=\"{$row['UserIndex']} class=\"studentUL\"\"><label><a>{$row['LName']}, {$row['FName']}, {$row['Year']}</a></label>";
如果我搜索,它会显示 this 如果我不搜索任何内容,它会显示 this
感谢您的帮助:)
最佳答案
我已经解决了这个问题。我基本上将所有内容都用 p 括起来,并编辑了我的 css 以对 p 产生影响。
这是新代码
echo"<p><a><input type=\"checkbox\" name=\"check_list[]\" value=\"{$row['UserIndex']} class=\"studentUL\"\"><label>{$row['LName']}, {$row['FName']}, {$row['Year']}</a></label></p>";
这对于 Jquery
function studentFunction() {
var input, filter, form, p, a, i;
input = document.getElementById("studentInput");
filter = input.value.toUpperCase();
form = document.getElementById("studentUL");
p = form.getElementsByTagName("p");
for (i = 0; i < p.length; i++) {
a = p[i].getElementsByTagName("a")[0];
if (a.innerHTML.toUpperCase().indexOf(filter) > -1) {
p[i].style.display = "";
} else {
p[i].style.display = "none";
}
}
}
关于javascript - 复选框上的 Jquery 搜索建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41051460/