我尝试使用输入从文本字段中搜索xml文件。我能够遍历文件并将字符串与彼此进行比较,因此如果字符串完全相同,它们基本匹配。我希望能够只用一个单词进行搜索,找到包含该单词的所有结果。
换句话说,如果我搜索“lorem”,我希望它能找到“lorem ipsum”。
function searchXML(){
$.get("xml/ResolvedIssues.xml",{},function(xml){
input = document.getElementById("inputSearch").value;
myHTMLOutput = '';
myHTMLOutput += '<h3>Tickets containing "';
myHTMLOutput += input;
myHTMLOutput += '"</h3>'
$('Table1',xml).each(function(i) {
application = $(this).find("Application").text();
module = $(this).find("Module").text();
ticket = $(this).find("Ticket_x0023_").text();
summary = $(this).find("Summary").text();
detail= $(this).find("Details").text();
problem = $(this).find("Problem_Flag").text();
version = $(this).find("Version").text();
build = $(this).find("Build").text();
checked = $(this).find("Checked_In").text();
status = $(this).find("Status").text();
if (input == module || input == ticket || input == summary ||
input == detail || input == problem || input == version ||
input == build || input == checked || input == status) {
$('#demo').html('');
mydata = BuildTable(application, module, ticket, summary, detail, problem, version, build, checked, status);
myHTMLOutput = myHTMLOutput + mydata;
};
});
$("#demo").append(myHTMLOutput);
});
}
答案 0 :(得分:1)
而不是这样做:
if (input == module || input == ticket || input == summary ||
input == detail || input == problem || input == version ||
input == build || input == checked || input == status) {
请改为尝试:
if ((module + ticket + summary + detail + problem + version +
build + checked + status).indexOf(input) > -1) {
答案 1 :(得分:0)