我希望有人可以带领我解决我的问题。我想在内部网页中建立一个搜索功能,其目的是为每个使用员工ID(例如4354111,4354222)的员工提供一个搜索字段,每个员工都有一个HTML资料页面。我想通过使用职员ID进行搜索来拉出特定页面。但是我目前正在失去资源..希望您的助手。谢谢!
enter code here <input type="text" placeholder="Search..">
enter code here <button onclick="loadFile()">Load file</button>
enter code here <script>
enter code here function loadFile() {
var reader = new XMLHttpRequest() || new ActiveXObject('MSXML2.XMLHTTP');
reader.open('get', '4354111.html', true);
reader.onreadystatechange = function () {
if (reader.readyState == 4 && reader.status == 200) {
displayContents(reader.responseText);
}
};
reader.send();
enter code here }
enter code here function displayContents(content) {
var wanted = '4354111';
var words = content.split(/\s/);
var found = [];
words.forEach(function (word, index) {
if (word === wanted && words[index + 1]) {
// push the next item (word) to the "wanted" array
found.push(words[index + 1]);
}
});
console.log('found:', found);
var el = document.getElementById('4354111');
el.innerHTML = found.length ? found.join('<br/>') : 'nothing found';
enter code here }
enter code here </script>