简体   繁体   English

如何使用jQuery自动完成项重定向到另一个页面

[英]How to redirect to another page with jQuery Autocomplete item click

I need to redirect to another page when I click to Autocomplate Text Box . 单击“自动填充文本框”时,需要重定向到另一页。 I try to put 我试着放

select: function(event, ui) {
                            window.location.href = 'Search.aspx?q=' + ui.item.value;;
                        },

but it does not work when i click? 但单击后不起作用? What am ı need to solve this ? 我需要解决什么?

    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>


 <script type="text/javascript">
        $(document).ready(function () {
            SearchText();
        });
        function SearchText() {
            $(".autosuggest").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "AutoCompleteService.asmx/GetAutoCompleteData",
                        data: "{'TurAdi':'" + document.getElementById('txtSearch').value + "'}",
                        idm: document.getElementById('txtSearch').value,
                        dataType: "json",
                        success: function (data) {
                            response(data.d);
                        },
                        select: function(event, ui) {
                            window.location.href = 'Search.aspx?q=' + ui.item.value;;
                        },
                        error: function (result) {
                            alert("Error");
                        }
                    });
                }
            });
        }

    </script>


 <asp:TextBox ID="txtSearch" runat="server" CssClass="searchtxtb oval autosuggest" Width="172px"  Height="25px"  BackColor="White"  Font-Bold="True" ForeColor="#666666" onfocus="if(this.value =='ARA:Tur, bölge veya belde adı' ) this.value=''"
                           onblur="if(this.value=='') this.value='ARA:Tur, bölge veya belde adı'" value="ARA:Tur, bölge veya belde adı"></asp:TextBox> 

The select: function (event, ui) { ... } should be moved to be a sibling of source , because it is an option of autocomplete not of ajax . 应该将select: function (event, ui) { ... }移至source的同级对象,因为它是autocomplete而非ajax的选项。

Like this - 像这样 -

 <script type="text/javascript">
        $(document).ready(function () {
            SearchText();
        });
        function SearchText() {
            $(".autosuggest").autocomplete({
                // Put it here, as part of the autocomplete options.
                select: function(event, ui) {
                    window.location.href = 'Search.aspx?q=' + ui.item.value;;
                },
                source: function (request, response) {
                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "AutoCompleteService.asmx/GetAutoCompleteData",
                        data: "{'TurAdi':'" + document.getElementById('txtSearch').value + "'}",
                        idm: document.getElementById('txtSearch').value,
                        dataType: "json",
                        success: function (data) {
                            response(data.d);
                        },

                        // Moved out of here, since it was an ajax
                        // option and it is unrelated to ajax.

                        error: function (result) {
                            alert("Error");
                        }
                    });
                }
            });
        }

    </script>


 <asp:TextBox ID="txtSearch" runat="server" CssClass="searchtxtb oval autosuggest" Width="172px"  Height="25px"  BackColor="White"  Font-Bold="True" ForeColor="#666666" onfocus="if(this.value =='ARA:Tur, bölge veya belde adı' ) this.value=''"
                           onblur="if(this.value=='') this.value='ARA:Tur, bölge veya belde adı'" value="ARA:Tur, bölge veya belde adı"></asp:TextBox> 

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

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