如何使用jQuery在HTML表格中显示JSON数据?如何在搜索结果时不区分大小写?
期望输出:
我该如何将结果显示在表格中?如何实现这一点?
期望输出:
![enter image description here](https://istack.dev59.com/plifo.webp)
var data = [{
"username": "John Doe",
"email": "jn@gmail.com",
"skills": "java,c,html,css"
},
{
"username": "Jane Smith",
"email": "js@gmail.com",
"skills": "java,sql"
},
{
"username": "Chuck Berry",
"email": "cb@gmail.com",
"skills": "vuejs"
}
];
/* Get Result */
function getResult() {
/* Read value from input fields */
var skills = $("#skills").val() || '',
email = $("#email").val() || '',
username = $("#username").val() || '';
var result = [],
i;
for (i = 0; i < data.length; i++) {
if ((skills !== '' && data[i]["skills"].indexOf(skills) !== -1) || (data[i]["email"] === email) || (
data[i]["username"] === username)) {
result.push(data[i]);
}
}
return result;
};
$('#submit').click(function onClick() {
var output = getResult();
console.log(output);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="skills" type="text" placeholder="skills">
<input id="email" type="email" placeholder="mail id">
<input id="username" type="text" placeholder="username">
<input id="submit" type="submit" value="submit">
str1.toUpperCase() == str2.toUpperCase()
。您已经尝试过以表格形式显示结果了吗?可以尝试使用jqueryObject.append()
开始。 - Ruzihm