I want a html button with parameter functionality.
我想要一个带参数功能的html按钮。
new/?sorting=desc
is the url that it should link to. But when I try, the parameter is not passed. How should it be done? I tried both the methods below but none worked.
new /?sorting = desc是它应链接到的url。但是当我尝试时,参数不会被传递。应该怎么做?我尝试了以下两种方法但没有效果。
<FORM METHOD="GET" ACTION="./?sorting=desc">
<INPUT TYPE="submit" VALUE="Äldst först">
</FORM>
I want buttons that behave like these links:
我想按行为像这些链接:
<a href="./?sorting=desc">Äldst först</a> <a href="./?sorting=asc">Nyast först</a>
3 个解决方案
#1
If you want something to act as a link, then you should use a link.
如果您想要某些东西充当链接,那么您应该使用链接。
That said:
When you submit a GET form, the query string is removed from the action and a new one is generated from the data in the form.
提交GET表单时,将从操作中删除查询字符串,并从表单中的数据生成新字符串。
You need to store the data in hidden inputs.
您需要将数据存储在隐藏的输入中。
<form action="/social/tracking/new/">
<input type="hidden"
name="sorting"
value="desc">
<input type="submit"
value="Nyast först">
</form>
<form action="/social/tracking/new/">
<input type="hidden"
name="sorting"
value="asc">
<input type="submit"
value="Sort the other way">
</form>
#2
If you are using jQuery, you can use the code below. This will fill a hidden input with the correct value when you click on one of the submit buttons.
如果您使用的是jQuery,则可以使用以下代码。当您单击其中一个提交按钮时,这将使用正确的值填充隐藏的输入。
<form method="get" action="./">
<input type="hidden" name="sorting" id="sorting" value="" />
<input type="submit" value="Äldst först" id="sort_desc" />
<input type="submit" value="Nyast först" id="sort_asc" />
</form>
<script>
$('#sort_desc').click(function(){
$('#sorting').val('desc');
});
$('#sort_asc').click(function(){
$('#sorting').val('asc');
});
</script>
#3
I think its not possible. A form is used to send data (mostly) via POST or GET. Your goal is to open a specific URL. I would create a standard and would style it like a button. Whats the reason you want to use a button?
我认为这是不可能的。表单用于(通常)通过POST或GET发送数据。您的目标是打开特定的URL。我会创建一个标准,并将其设置为按钮。你想要使用按钮的原因是什么?
#1
If you want something to act as a link, then you should use a link.
如果您想要某些东西充当链接,那么您应该使用链接。
That said:
When you submit a GET form, the query string is removed from the action and a new one is generated from the data in the form.
提交GET表单时,将从操作中删除查询字符串,并从表单中的数据生成新字符串。
You need to store the data in hidden inputs.
您需要将数据存储在隐藏的输入中。
<form action="/social/tracking/new/">
<input type="hidden"
name="sorting"
value="desc">
<input type="submit"
value="Nyast först">
</form>
<form action="/social/tracking/new/">
<input type="hidden"
name="sorting"
value="asc">
<input type="submit"
value="Sort the other way">
</form>
#2
If you are using jQuery, you can use the code below. This will fill a hidden input with the correct value when you click on one of the submit buttons.
如果您使用的是jQuery,则可以使用以下代码。当您单击其中一个提交按钮时,这将使用正确的值填充隐藏的输入。
<form method="get" action="./">
<input type="hidden" name="sorting" id="sorting" value="" />
<input type="submit" value="Äldst först" id="sort_desc" />
<input type="submit" value="Nyast först" id="sort_asc" />
</form>
<script>
$('#sort_desc').click(function(){
$('#sorting').val('desc');
});
$('#sort_asc').click(function(){
$('#sorting').val('asc');
});
</script>
#3
I think its not possible. A form is used to send data (mostly) via POST or GET. Your goal is to open a specific URL. I would create a standard and would style it like a button. Whats the reason you want to use a button?
我认为这是不可能的。表单用于(通常)通过POST或GET发送数据。您的目标是打开特定的URL。我会创建一个标准,并将其设置为按钮。你想要使用按钮的原因是什么?