如何防止使用 GET 方法的表单发送提交按钮的值?
我有一个简单的表单:
<form action="/search" method="get">
<input type="text" name="q" value="">
<input type="submit" name="search" value="search">
</form>
提交时,网址变为 `/search?q=Loremipsum&
search=search
我真的不希望这样最后一点,这似乎是一个很常见的问题,我认为它可以在没有js的情况下解决,但我意识到,当你点击搜索按钮时,即使是google.com也有这个问题。 (也许他们不太关心丑陋的网址?)
search?hl=en&source=hp&q=Loremipsum&
btnG=Google+Search
< /strong>&aq=f&..
有没有办法防止提交按钮的值在没有 JavaScript 的情况下被排除?
我在堆栈溢出中看到搜索是 ?q=
但他们没有提交按钮。
I have a simple form:
<form action="/search" method="get">
<input type="text" name="q" value="">
<input type="submit" name="search" value="search">
</form>
When submitting the url becomes `/search?q=Loremipsum&
search=search
I really don't want that last bit, this seems pretty common problem and think it could be solved without js, but I realized that even google.com has this problem when you click on the search button. (maybe they don't care much about ugly urls?)
search?hl=en&source=hp&q=Loremipsum&
btnG=Google+Search
&aq=f&..
Is there a way to prevent the value of the submit button to be excluded without javascript?
I see in Stack overflow the search is ?q=
but they don't have a submit button.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在最终输入中省略 name 属性,如下所示:
应该可以解决问题。保留
value
属性允许您操纵按钮上显示的文本。You can omit name attribute in the final input like this:
Should do the trick. Keeping
value
attribute allows you to manipulate what text is displayed on the button.作为记录,如果您愿意,您也可以省略提交按钮,当您输入搜索词后按回车键时,表单将提交。 (这就是 Stack Overflow 搜索框的工作原理)。
For the record, you can also omit the submit button if you like, and the form will submit when you press return after typing your search term. (This is how the Stack Overflow search box works).