通过锚点将数据从一个输入框获取到另一个页面上的另一个输入

时间:2015-11-11 06:28:27

标签: javascript html anchor

我在索引页面上有一个搜索输入框,我希望它重定向到搜索页面,并自动用输入框中的文本填充搜索框,然后手动触发.keyUp()事件。
我是javascript和html的初学者,所以请原谅我糟糕的编码 这是我当前的index.html页面代码:

<div class="address-bar">
    <input id="search-text" type="text">
    <button id="search-enter">Search</button>
</div>

我的该页面的javascript是:

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script>

    var searchquery = $("#search-text")
    $("#search-enter").click(redirect)
    function redirect() {
        window.location("http://<example>.com/search.html#q=" + searchquery + "E")
    }
</script>

我目前正在使用Matt york's fuzzy search libary。 我的另一页上的代码是:

<h1>Search:</h1>
<input type="text" id="search" class="search"></input>
<div id="characters">
</div>

使用javascript:

<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script>
var anchor = window.location.hash()
var question = anchor.substring(3, -1)

1 个答案:

答案 0 :(得分:0)

试试这个

$('.search').val(question);
$('.search').keyup();

那说你可能想给输入元素一个id。

相关问题