简体   繁体   English

格式化来自的搜索结果 <input> ?

[英]Format Search results from <input>?

I am trying to make a search bar. 我正在尝试创建一个搜索栏。 I am building a multi-page mobile app and the search bar will be used to search for pages for quick navigation. 我正在构建一个多页移动应用程序,搜索栏将用于搜索页面以进行快速导航。 my pages are stored in a data.JSON file, that I am putting in local storage so they can be accessed offline. 我的页面存储在data.JSON文件中,我将其放入本地存储中,以便可以脱机访问它们。 The question is, How can I format it so that when the user searches for a page, the results will be displayed in a list that pops up under the search bar that users can click on that will navigate them to that page? 问题是,如何格式化它,以便当用户搜索页面时,结果将显示在搜索栏下方弹出的列表中,用户可以单击该列表将其导航到该页面?

//search page// //搜索页//

<div data-role="page" id="SearchPage">
<div data-role="fieldcontain">

<input type="search" name="search" id="SearchView" value="search" placeholder="Search" align="center"/>
 </div> 

//Appartment Page// //公寓页面//

<div data-role="page" id="AppartmentPage" class="page">
<h1 class="TopText" id="AppartmentT">Apartment</h1>
<img class="Image" src="images/appartment.png" alt="Appartment"/>
<h1 class="BotText" id="AppartmentB">Apartment</h1>
</div>

//data.JSON// //data.JSON//

{
 "pages":[
    "Appartment": "Appartment",
    "bed and breakfast": "bed and breakfast"
    "house": "house"
    ]
}

//script// //脚本//

<script type="text/javascript">
$(function () {
    $.getJSON("data.json", function (data) {
        localStorage.setItem('pages', JSON.stringify(data));
    });
});
$(function () {
    $.getJSON("data.json", function (data) {
        localStorage.setItem('languages', JSON.stringify(data));
    });
});
var pages = JSON.parse(localStorage.getItem('pages'));
if (pages != null) {
for (var i = 0; i < pages.length; i++) {
    alert(pages[i]);
}
}
</script>

my goal is to make the search bar look/function similar to the one in the image below. 我的目标是使搜索栏的外观/功能类似于下图所示。

在此处输入图片说明

You can use Autocomplete for this.Append all our pages as <li> . 您可以为此使用Autocomplete ,将所有页面添加为<li> There you can give the href link for every <li> like following : 您可以在其中为每个<li>提供href链接,如下所示:

<li><a href="#yourPageURL">Page1</a></li>

Or onclick of that <li> you can navigate to the particular page.Check this reference link 或者onclick<li>您可以导航到特定页面。查看此参考链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM