从表单提交更改URL哈希 [英] Changing an URL hash from a form submit

查看:81
本文介绍了从表单提交更改URL哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 < form action =/ searchid =搜索形式> 
< input type =textid =search-inputname =sx-webkit-speech>
< / form>

正确地重定向到 / search?s = searchvalue 但我怎么能改变它到 / search#s = searchvalue 使用javascript?

解决方案<

 < form action =/ searchid = search-form
onsubmit =location.href = this.action +'#s ='+ this.s.value; return false;>
< input type =textid =search-inputname =sx-webkit-speech>
< / form>

另请参阅此提琴手: http://jsfiddle.net/SujwN/


On my index.html I have the following form:

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

Which correctly redirects to /search?s=searchvalue but how could I change that to /search#s=searchvalue using javascript?

解决方案

Well not with jQuery but that should work:

<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>

See also this fiddler: http://jsfiddle.net/SujwN/

这篇关于从表单提交更改URL哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆