使用表单操作向URL添加哈希“#”符号? [英] Appending a hash '#' symbol to url with a form action?
问题描述
所以我有一个带有提交按钮和文本输入的表单...
So I've got a form with a submit button and a text input...
我在javascript中做了一个解决方案,涉及到使用哈希onclick将表单的动作更改为url ..但这在IE中不起作用。
I did a solution in javascript which involves changing the "action" of the form to the url with the hash onclick.. but this doesn't work in IE.
任何人都有适用于所有浏览器的解决方案吗?
Anyone have a solution that works on all browsers?
推荐答案
我遇到了类似的问题,IE没有从表单操作中提取哈希。
I ran into a similar problem with IE not pulling in the hash from the form action.
我有一个表单
<form action="/#search" id="search-form">
<input type="text" class="search-query" placeholder="Search" name="q">
</form>
当我在IE中提交此表格时,页面转到了
When I submitted this form in anything but IE the page went to
/?q = searchparams #search
但是在IE中它去了
/?q = searchparams
要解决这个问题我使用JQuery绑定到提交操作并重定向到我希望它去的页面。
To solve this I used JQuery to bind to the submit action and redirect to the page I wanted it to go to.
$("#search-form").submit(function() {
var query = $('input[name="q"]').val();
window.location.href = 'index.php?q='+query+'#search';
return false;
});
自那以来一切正常。
这篇关于使用表单操作向URL添加哈希“#”符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!