gpt4 book ai didi

javascript - 从表单提交更改 URL 哈希

转载 作者:搜寻专家 更新时间:2023-10-31 21:59:38 25 4
gpt4 key购买 nike

在我的 index.html 上,我有以下形式:

<form action="/search" id="search-form">
<input type="text" id="search-input" name="s" x-webkit-speech>
</form>

哪个正确重定向到 /search?s=searchvalue 但我如何使用 javascript 将其更改为 /search#s=searchvalue

最佳答案

虽然 jQuery 不行,但应该可以:

<form action="/search" id="search-form"
onsubmit="location.href=this.action+'#s='+this.s.value; return false;">
<input type="text" id="search-input" name="s" x-webkit-speech>
</form>

另请参阅此 fiddler :http://jsfiddle.net/SujwN/

关于javascript - 从表单提交更改 URL 哈希,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13542265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com