简体   繁体   English

Searchbar网站:按页面标题而不是页面链接Javascript搜索

[英]Searchbar website : search by page title instead of page link Javascript

So i'v found this code to search other pages from the main page of my website, and it works great, but the autocomplete shows the link of the page instead of the title of the page , can anyone help me to modify the code ? 因此,我发现该代码可以从我的网站主页上搜索其他页面,并且效果很好,但是自动完成功能显示的是页面链接而不是页面标题,有人可以帮我修改代码吗?

<form id="form1" runat="server" class="online-form">
    <div class="ui-widget">
        <input id="tags" class="form-control" placeholder="Rechercher un service…" required="" />
    </div>
</form>
<script>
$(function () {
    var availableTags = ["page1.html","page2.html","page3.html"];
    $("#tags").autocomplete({
        source: availableTags,
        select: function (e, ui) {
            var value = ui.item.value;
            window.location.href = "../" + value;
        },
    });
});
</script>

The best way to make what you want and still continuing using jQuery's autocomplete is to create an additional array with the links. 做出您想要的并且仍然继续使用jQuery的自动完成功能的最佳方法是使用链接创建一个附加数组。 On select we will check the position of the AvailableTags array and then use the new array for the redirect. 选择时,我们将检查AvailableTags数组的位置,然后将新数组用于重定向。

<script>
    $(function () {
        var availableTags = ["Page 1", "Page 2"];
        var availableTagsLinks = ["page1.htm", "page2.htm"];
        $("#tags").autocomplete({
            source: availableTags,
            select: function (e, ui) {
                var value = ui.item.value;
                var indexPos = $.inArray(ui.item.value, availableTags);
                window.location.href = "../" + availableTagsLinks[indexPos];
            },
        });
    });
</script>

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

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