我在索引页上有一个搜索输入框,我希望它重定向到搜索页面,并自动用输入框中的文本填充搜索框,然后手动触发.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>我目前正在使用马特·约克的模糊搜索词典。我另一页上的代码是:
<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)发布于 2015-11-11 06:36:32
尝尝这个
$('.search').val(question);
$('.search').keyup();这就是说,您可能需要给输入元素一个id。
https://stackoverflow.com/questions/33645329
复制相似问题