簡體   English   中英

點擊搜索欄上的鏈接

[英]Search bar on click go to link

我有一個搜索欄,它可以建議數據庫中的用戶。 當前,當單擊用戶名時,實際上什么也沒發生,用戶名轉到搜索欄,但是我該怎么做,以便在單擊用戶名時轉到鏈接並在其后添加用戶名。

例如:www.test.com/user.php?u=((用戶名))

<script type="text/javascript">
$(document).ready(function(){
    $('.search-box input[type="text"]').on("keyup input", function(){
        /* Get input value on change */
        var inputVal = $(this).val();
        var resultDropdown = $(this).siblings(".result");
        if(inputVal.length){
            $.get("backend-search.php", {term: inputVal}).done(function(data){
                // Display the returned data in browser
                resultDropdown.html(data);
            });
        } else{
            resultDropdown.empty();
        }
    });

    // Set search input value on click of result item
    $(document).on("click", ".result p", function(){
        $(this).parents(".search-box").find('input[type="text"]').val($(this).text());
        $(this).parent(".result").empty();
    });
});
</script>

您可以通過更改window.location.href值導航到頁面。 因此,您可以執行以下操作:

$(document).on("click", ".result p", function(){
    $(this).parents(".search-box").find('input[type="text"]').val($(this).text());
    $(this).parent(".result").empty();
    window.location.href = 'www.test.com/user.php?u=' + $(this).text();
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM